10 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_THREADING_H 11 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_THREADING_H 15 #include "llvm/ADT/Twine.h" 17 #include <condition_variable> 35 bool Notified =
false;
36 mutable std::condition_variable CV;
37 mutable std::mutex Mu;
51 std::condition_variable SlotsChanged;
52 std::size_t FreeSlots;
60 Deadline(std::chrono::steady_clock::time_point Time)
61 : Type(Finite), Time(Time) {}
65 std::chrono::steady_clock::time_point
time()
const {
66 assert(Type == Finite);
70 return (Type == Zero) ||
71 (Type == Finite && Time < std::chrono::steady_clock::now());
74 return (Type == Other.Type) && (Type != Finite || Time == Other.Time);
78 enum Type { Zero, Infinite, Finite };
80 Deadline(
enum Type Type) : Type(Type) {}
82 std::chrono::steady_clock::time_point Time;
88 void wait(std::unique_lock<std::mutex> &Lock, std::condition_variable &CV,
91 template <
typename Func>
92 LLVM_NODISCARD
bool wait(std::unique_lock<std::mutex> &Lock,
93 std::condition_variable &CV,
Deadline D, Func F) {
116 mutable std::mutex Mutex;
117 mutable std::condition_variable TasksReachedZero;
118 std::size_t InFlightTasks = 0;
A threadsafe flag that is initially clear.
void preventThreadStarvationInTests()
bool operator==(const Deadline &Other) const
Limits the number of threads that can acquire the lock at the same time.
std::future< T > runAsync(llvm::unique_function< T()> Action)
Runs Action asynchronously with a new std::thread.
static Deadline infinity()
llvm::unique_function< void()> Action
static constexpr llvm::StringLiteral Name
Runs tasks on separate (detached) threads and wait for all tasks to finish.
void setCurrentThreadPriority(ThreadPriority Priority)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Deadline timeoutSeconds(llvm::Optional< double > Seconds)
Makes a deadline from a timeout in seconds. None means wait forever.
Deadline(std::chrono::steady_clock::time_point Time)
A point in time we can wait for.
std::chrono::steady_clock::time_point time() const