summaryrefslogtreecommitdiffstats
path: root/lldb/source/Host/windows/HostInfoWindows.cpp
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@apple.com>2015-02-03 02:05:44 +0000
committerGreg Clayton <gclayton@apple.com>2015-02-03 02:05:44 +0000
commitff48e4bea09afe020e1c4373f32b65a8be29503e (patch)
treead505060c757c203697691b84e72c9857762f111 /lldb/source/Host/windows/HostInfoWindows.cpp
parentdcfd6ed1837c4a162c8315d9f5b19cdd2a67a016 (diff)
downloadbcm5719-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/windows/HostInfoWindows.cpp')
-rw-r--r--lldb/source/Host/windows/HostInfoWindows.cpp15
1 files changed, 7 insertions, 8 deletions
diff --git a/lldb/source/Host/windows/HostInfoWindows.cpp b/lldb/source/Host/windows/HostInfoWindows.cpp
index c0366dd47bc..a2b599461c7 100644
--- a/lldb/source/Host/windows/HostInfoWindows.cpp
+++ b/lldb/source/Host/windows/HostInfoWindows.cpp
@@ -9,6 +9,8 @@
#include "lldb/Host/windows/windows.h"
+#include <mutex> // std::once
+
#include "lldb/Host/windows/HostInfoWindows.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Support/raw_ostream.h"
@@ -84,14 +86,11 @@ HostInfoWindows::GetHostname(std::string &s)
FileSpec
HostInfoWindows::GetProgramFileSpec()
{
- static bool is_initialized = false;
- if (!is_initialized)
- {
- is_initialized = true;
-
- std::vector<char> buffer(PATH_MAX);
- ::GetModuleFileName(NULL, &buffer[0], buffer.size());
- m_program_filespec.SetFile(&buffer[0], false);
+ static std::once_flag g_once_flag;
+ std::call_once(g_once_flag, []() {
+ char buffer[PATH_MAX];
+ ::GetModuleFileName(NULL, buffer, sizeof(buffer));
+ m_program_filespec.SetFile(buffer, false);
}
return m_program_filespec;
}
OpenPOWER on IntegriCloud