diff options
author | B. Stack <bgstack15@gmail.com> | 2023-07-24 15:08:16 -0400 |
---|---|---|
committer | B. Stack <bgstack15@gmail.com> | 2023-07-24 15:08:16 -0400 |
commit | 69e12f5bd10459ff7c239b82519107ae2a755bc0 (patch) | |
tree | 8b22393241df7e46686c9426140582bd747a6d5a /zen/file_path.cpp | |
parent | add upstream 12.4 (diff) | |
download | FreeFileSync-69e12f5bd10459ff7c239b82519107ae2a755bc0.tar.gz FreeFileSync-69e12f5bd10459ff7c239b82519107ae2a755bc0.tar.bz2 FreeFileSync-69e12f5bd10459ff7c239b82519107ae2a755bc0.zip |
add upstream 12.5
Diffstat (limited to 'zen/file_path.cpp')
-rw-r--r-- | zen/file_path.cpp | 32 |
1 files changed, 9 insertions, 23 deletions
diff --git a/zen/file_path.cpp b/zen/file_path.cpp index 60ac4eb7..6503ba2f 100644 --- a/zen/file_path.cpp +++ b/zen/file_path.cpp @@ -173,13 +173,6 @@ std::unordered_map<Zstring, Zstring> getAllEnvVars() } constinit Global<std::unordered_map<Zstring, Zstring>> globalEnvVars; -GLOBAL_RUN_ONCE( - //*INDENT-OFF* - //mitigate static initialization order fiasco: (whatever comes first) - if (!globalEnvVars.get()) - globalEnvVars.set(std::make_unique<std::unordered_map<Zstring, Zstring>>(getAllEnvVars())) - //*INDENT-ON* -); } @@ -191,24 +184,17 @@ std::optional<Zstring> zen::getEnvironmentVar(const ZstringView name) getenv_s() to the rescue!? not implemented on GCC, apparently *still* not threadsafe!!! => *eff* this: make a global copy during start up! */ - std::shared_ptr<std::unordered_map<Zstring, Zstring>> envVars = globalEnvVars.get(); - if (!envVars) //access during static init or shutdown? + globalEnvVars.setOnce([] { return std::make_unique<std::unordered_map<Zstring, Zstring>>(getAllEnvVars()); }); + + if (std::shared_ptr<std::unordered_map<Zstring, Zstring>> envVars = globalEnvVars.get()) { - if (globalEnvVars.wasDestroyed()) - { - assert(false); - return {}; //SOL! - } - //mitigate static initialization order fiasco: (whatever comes first) - globalEnvVars.set(std::make_unique<std::unordered_map<Zstring, Zstring>>(getAllEnvVars())); - envVars = globalEnvVars.get(); + if (const auto it = envVars->find(name); + it != envVars->end()) + return it->second; } - - const auto it = envVars->find(name); - if (it == envVars->end()) - return {}; - - return it->second; + else + assert(false); //access during global shutdown => SOL! + return {}; } |