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> 34 bool Notified =
false;
35 mutable std::condition_variable CV;
36 mutable std::mutex Mu;
49 std::condition_variable SlotsChanged;
50 std::size_t FreeSlots;
58 Deadline(std::chrono::steady_clock::time_point Time)
59 : Type(Finite), Time(Time) {}
63 std::chrono::steady_clock::time_point
time()
const {
64 assert(Type == Finite);
68 return (Type == Zero) ||
69 (Type == Finite && Time < std::chrono::steady_clock::now());
72 return (Type == Other.Type) && (Type != Finite || Time == Other.Time);
76 enum Type { Zero, Infinite, Finite };
78 Deadline(
enum Type Type) : Type(Type) {}
80 std::chrono::steady_clock::time_point Time;
86 void wait(std::unique_lock<std::mutex> &Lock, std::condition_variable &CV,
89 template <
typename Func>
90 LLVM_NODISCARD
bool wait(std::unique_lock<std::mutex> &Lock,
91 std::condition_variable &CV,
Deadline D, Func F) {
111 void runAsync(
const llvm::Twine &
Name, llvm::unique_function<
void()>
Action);
114 mutable std::mutex Mutex;
115 mutable std::condition_variable TasksReachedZero;
116 std::size_t InFlightTasks = 0;
A threadsafe flag that is initially clear.
bool operator==(const Deadline &Other) const
Limits the number of threads that can acquire the lock at the same time.
static Deadline infinity()
llvm::unique_function< void()> Action
Runs tasks on separate (detached) threads and wait for all tasks to finish.
===– 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