diff options
author | Greg Clayton <gclayton@apple.com> | 2015-02-03 02:05:44 +0000 |
---|---|---|
committer | Greg Clayton <gclayton@apple.com> | 2015-02-03 02:05:44 +0000 |
commit | ff48e4bea09afe020e1c4373f32b65a8be29503e (patch) | |
tree | ad505060c757c203697691b84e72c9857762f111 /lldb/source/Host/linux/HostInfoLinux.cpp | |
parent | dcfd6ed1837c4a162c8315d9f5b19cdd2a67a016 (diff) | |
download | bcm5719-llvm-ff48e4bea09afe020e1c4373f32b65a8be29503e.tar.gz bcm5719-llvm-ff48e4bea09afe020e1c4373f32b65a8be29503e.zip |
Fixed bugs in the multi-threaded access in HostInfoBase. Prior to this fix, static bool variables were used but this is not sufficient. We now use std::call_once in all places where the previous static bool code was used to try to implement thread safety.
This was causing code that opened multiple targets to try and get a path to debugserver from the GDB remote communication class, and it would get the LLDB path and some instances would return empty strings and it would cause debugserver to not be found.
<rdar://problem/18756927>
llvm-svn: 227935
Diffstat (limited to 'lldb/source/Host/linux/HostInfoLinux.cpp')
-rw-r--r-- | lldb/source/Host/linux/HostInfoLinux.cpp | 46 |
1 files changed, 21 insertions, 25 deletions
diff --git a/lldb/source/Host/linux/HostInfoLinux.cpp b/lldb/source/Host/linux/HostInfoLinux.cpp index bace2586aad..bca92ec9961 100644 --- a/lldb/source/Host/linux/HostInfoLinux.cpp +++ b/lldb/source/Host/linux/HostInfoLinux.cpp @@ -16,6 +16,7 @@ #include <sys/utsname.h> #include <algorithm> +#include <mutex> // std::once using namespace lldb_private; @@ -56,32 +57,29 @@ HostInfoLinux::GetMaxThreadNameLength() bool HostInfoLinux::GetOSVersion(uint32_t &major, uint32_t &minor, uint32_t &update) { - static bool is_initialized = false; static bool success = false; + static std::once_flag g_once_flag; + std::call_once(g_once_flag, []() { - if (!is_initialized) - { - is_initialized = true; struct utsname un; - - if (uname(&un)) - goto finished; - - int status = sscanf(un.release, "%u.%u.%u", &g_fields->m_os_major, &g_fields->m_os_minor, &g_fields->m_os_update); - if (status == 3) + if (uname(&un) == 0) { - success = true; - goto finished; + int status = sscanf(un.release, "%u.%u.%u", &g_fields->m_os_major, &g_fields->m_os_minor, &g_fields->m_os_update); + if (status == 3) + success = true; + else + { + // Some kernels omit the update version, so try looking for just "X.Y" and + // set update to 0. + g_fields->m_os_update = 0; + status = sscanf(un.release, "%u.%u", &g_fields->m_os_major, &g_fields->m_os_minor); + if (status == 2) + success = true; + } } + }); - // Some kernels omit the update version, so try looking for just "X.Y" and - // set update to 0. - g_fields->m_os_update = 0; - status = sscanf(un.release, "%u.%u", &g_fields->m_os_major, &g_fields->m_os_minor); - success = !!(status == 2); - } -finished: major = g_fields->m_os_major; minor = g_fields->m_os_minor; update = g_fields->m_os_update; @@ -120,13 +118,11 @@ HostInfoLinux::GetOSKernelDescription(std::string &s) llvm::StringRef HostInfoLinux::GetDistributionId() { - static bool is_initialized = false; // Try to run 'lbs_release -i', and use that response // for the distribution id. - - if (!is_initialized) - { - is_initialized = true; + static bool success = false; + static std::once_flag g_once_flag; + std::call_once(g_once_flag, []() { Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST)); if (log) @@ -202,7 +198,7 @@ HostInfoLinux::GetDistributionId() // clean up the file pclose(file); } - } + }); return g_fields->m_distribution_id.c_str(); } |