From 7f23ee90fd545995a29e2175f15e8b97e59ca67a Mon Sep 17 00:00:00 2001 From: Daniel Wilhelm Date: Fri, 18 Apr 2014 17:13:13 +0200 Subject: 3.20 --- shared/zstring.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'shared/zstring.cpp') diff --git a/shared/zstring.cpp b/shared/zstring.cpp index 2955ec3e..e1df17ee 100644 --- a/shared/zstring.cpp +++ b/shared/zstring.cpp @@ -3,9 +3,10 @@ // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * // * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** -// + #include "zstring.h" #include +#include #ifdef FFS_WIN #include //includes "windows.h" @@ -52,6 +53,12 @@ LeakChecker& LeakChecker::instance() return inst; } +//caveat: function scope static initialization is not thread-safe in VS 2010! => make sure to call at app start! +namespace +{ +struct Dummy { Dummy() { LeakChecker::instance(); }} blah; +} + std::string LeakChecker::rawMemToString(const void* ptr, size_t size) { @@ -113,7 +120,10 @@ int z_impl::compareFilenamesWin(const wchar_t* a, const wchar_t* b, size_t sizeA LPCWSTR lpString2, int cchCount2, BOOL bIgnoreCase); - static const CompareStringOrdinalFunc ordinalCompare = util::getDllFun(L"kernel32.dll", "CompareStringOrdinal"); + static CompareStringOrdinalFunc ordinalCompare = NULL; //caveat: function scope static initialization is not thread-safe in VS 2010! + static boost::once_flag once = BOOST_ONCE_INIT; + boost::call_once(once, []() { ordinalCompare = util::getDllFun(L"kernel32.dll", "CompareStringOrdinal"); }); + if (ordinalCompare != NULL) //this additional test has no noticeable performance impact { -- cgit