diff options
Diffstat (limited to 'clang-tools-extra/clangd/Context.cpp')
-rw-r--r-- | clang-tools-extra/clangd/Context.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/clang-tools-extra/clangd/Context.cpp b/clang-tools-extra/clangd/Context.cpp index d7a1a04b035..5a161216a25 100644 --- a/clang-tools-extra/clangd/Context.cpp +++ b/clang-tools-extra/clangd/Context.cpp @@ -20,5 +20,19 @@ Context::Context(std::shared_ptr<const Data> DataPtr) Context Context::clone() const { return Context(DataPtr); } +// The thread-local Context is scoped in a function to avoid +// initialization-order issues. It's created when first needed. +static Context ¤tContext() { + static thread_local Context C = Context::empty(); + return C; +} + +const Context &Context::current() { return currentContext(); } + +Context Context::swapCurrent(Context Replacement) { + std::swap(Replacement, currentContext()); + return Replacement; +} + } // namespace clangd } // namespace clang |