Browse Source

use std::call_once instead of bool flag

Andrey Filipenkov 2 years ago
parent
commit
59948a41a6
2 changed files with 3 additions and 6 deletions
  1. 1 0
      Global.h
  2. 2 6
      lib/VCMIDirs.cpp

+ 1 - 0
Global.h

@@ -138,6 +138,7 @@ static_assert(sizeof(bool) == 1, "Bool needs to be 1 byte in size.");
 #include <utility>
 #include <vector>
 #include <atomic>
+#include <mutex>
 
 //The only available version is 3, as of Boost 1.50
 #include <boost/version.hpp>

+ 2 - 6
lib/VCMIDirs.cpp

@@ -705,12 +705,8 @@ namespace VCMIDirs
 			static VCMIDirsIOS singleton;
 		#endif
 
-		static bool initialized = false;
-		if (!initialized)
-		{
-			singleton.init();
-			initialized = true;
-		}
+		static std::once_flag flag;
+		std::call_once(flag, [] { singleton.init(); });
 		return singleton;
 	}
 }