summaryrefslogtreecommitdiffstats
path: root/lldb/source/Host/linux/HostInfoLinux.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/source/Host/linux/HostInfoLinux.cpp')
-rw-r--r--lldb/source/Host/linux/HostInfoLinux.cpp46
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();
}
OpenPOWER on IntegriCloud