9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_THREADING_H 10 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_THREADING_H 14 #include "llvm/ADT/Twine.h" 16 #include <condition_variable> 34 bool Notified =
false;
35 mutable std::condition_variable CV;
36 mutable std::mutex Mu;
50 std::condition_variable SlotsChanged;
51 std::size_t FreeSlots;
59 Deadline(std::chrono::steady_clock::time_point Time)
60 : Type(Finite), Time(Time) {}
64 std::chrono::steady_clock::time_point
time()
const {
65 assert(Type == Finite);
69 return (Type == Zero) ||
70 (Type == Finite && Time < std::chrono::steady_clock::now());
73 return (Type == Other.Type) && (Type != Finite || Time == Other.Time);
77 enum Type { Zero, Infinite, Finite };
81 std::chrono::steady_clock::time_point Time;
87 void wait(std::unique_lock<std::mutex> &Lock, std::condition_variable &CV,
90 template <
typename Func>
91 LLVM_NODISCARD
bool wait(std::unique_lock<std::mutex> &Lock,
92 std::condition_variable &CV,
Deadline D, Func F) {
115 mutable std::mutex Mutex;
116 mutable std::condition_variable TasksReachedZero;
117 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.
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.
===– 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