[Lldb-commits] [PATCH] D29288: Switch std::call_once to llvm::call_once
Pavel Labath via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Sat Feb 4 17:26:51 PST 2017
labath added inline comments.
================
Comment at: include/lldb/Core/Debugger.h:379
lldb::ListenerSP m_forward_listener_sp;
- std::once_flag m_clear_once;
+ llvm::once_flag m_clear_once;
----------------
The code in llvm says you should only ever use the LLVM_DEFINE_ONCE_FLAG to declare flags. I am guessing it's because it forces the `static` keyword into the declaration, which in turn guarantees your object will be zero-initialized by the linker. If you declare the flag as a local variable like this, it will be initialized to a random value, and you will have a fun time debugging issues in the future (it will only affect netbsd, as std::call_once platforms will still be correctly initialized).
================
Comment at: source/Core/ModuleList.cpp:648
static ModuleList &GetSharedModuleList() {
static ModuleList *g_shared_module_list = nullptr;
+ LLVM_DEFINE_ONCE_FLAG(g_once_flag);
----------------
This could be simplified to:
```static ModuleList *g_shared_module_list = new ModuleList();```
It's only written this way because MSVC at one point did not support thread-safe statics.
Repository:
rL LLVM
https://reviews.llvm.org/D29288
More information about the lldb-commits
mailing list