blob: ae2354bbe02e0e125392e0c76cfa9400c1e19693 [file] [log] [blame]
//===--- Cancellation.cpp -----------------------------------------*-C++-*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "Cancellation.h"
#include <atomic>
namespace clang {
namespace clangd {
char CancelledError::ID = 0;
static Key<std::shared_ptr<std::atomic<bool>>> FlagKey;
std::pair<Context, Canceler> cancelableTask() {
auto Flag = std::make_shared<std::atomic<bool>>();
return {
Context::current().derive(FlagKey, Flag),
[Flag] { *Flag = true; },
};
}
bool isCancelled() {
if (auto *Flag = Context::current().get(FlagKey))
return **Flag;
return false; // Not in scope of a task.
}
} // namespace clangd
} // namespace clang