clang-tools 8.0.0

Cancellation.cpp
Go to the documentation of this file.
1 //===--- Cancellation.cpp -----------------------------------------*-C++-*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "Cancellation.h"
11 #include <atomic>
12
13 namespace clang {
14 namespace clangd {
15
16 char CancelledError::ID = 0;
17 static Key<std::shared_ptr<std::atomic<bool>>> FlagKey;
18
19 std::pair<Context, Canceler> cancelableTask() {
20 auto Flag = std::make_shared<std::atomic<bool>>();
21 return {
22 Context::current().derive(FlagKey, Flag),
23 [Flag] { *Flag = true; },
24 };
25 }
26
27 bool isCancelled(const Context &Ctx) {
28 if (auto *Flag = Ctx.get(FlagKey))
29 return **Flag;
30 return false; // Not in scope of a task.
31 }
32
33 } // namespace clangd
34 } // namespace clang
clang::clangd::CancelledError::ID
static char ID
Definition: Cancellation.h:87
clang::clangd::Key
Values in a Context are indexed by typed keys.
Definition: Context.h:41
clang::clangd::isCancelled
bool isCancelled(const Context &Ctx)
True if the current context is within a cancelable task which was cancelled.
Definition: Cancellation.cpp:27
Cancellation.h
clang::clangd::Context::get
const Type * get(const Key< Type > &Key) const
Get data stored for a typed Key.
Definition: Context.h:101
Ctx
Context Ctx
Definition: TUScheduler.cpp:224
clang::clangd::Context::current
static const Context & current()
Returns the context for the current thread, creating it if needed.
Definition: Context.cpp:28
clang::clangd::FlagKey
static Key< std::shared_ptr< std::atomic< bool > > > FlagKey
Definition: Cancellation.cpp:17
clang::clangd::cancelableTask
std::pair< Context, Canceler > cancelableTask()
Defines a new task whose cancellation may be requested.
Definition: Cancellation.cpp:19
clang::clangd::Context
A context is an immutable container for per-request data that must be propagated through layers that ...
Definition: Context.h:70
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ChangeNamespace.cpp:18
clang::clangd::Context::derive
Context derive(const Key< Type > &Key, typename std::decay< Type >::type Value) const &
Derives a child context It is safe to move or destroy a parent context after calling derive()...
Definition: Context.h:122