From ff48e4bea09afe020e1c4373f32b65a8be29503e Mon Sep 17 00:00:00 2001 From: Greg Clayton Date: Tue, 3 Feb 2015 02:05:44 +0000 Subject: 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. llvm-svn: 227935 --- lldb/source/Host/windows/HostInfoWindows.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'lldb/source/Host/windows/HostInfoWindows.cpp') 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 // 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 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; } -- cgit v1.2.3