24 std::optional<Task>
Task;
26 std::unique_lock<std::mutex> Lock(Mu);
27 CV.wait(Lock, [&] {
return ShouldStop || !Queue.empty(); });
34 std::pop_heap(Queue.begin(), Queue.end());
35 Task = std::move(Queue.back());
45 llvm::set_thread_priority(llvm::ThreadPriority::Default);
48 std::unique_lock<std::mutex> Lock(Mu);
50 if (Stat.
Active == 1 && Queue.empty()) {
60 assert(Stat.
Active > 0 &&
"before decrementing");
70 std::lock_guard<std::mutex> QueueLock(Mu);
77bool BackgroundQueue::adjust(Task &T) {
83 if (T.Key && !SeenKeys.insert(T.Key).second)
85 T.QueuePri = std::max(T.QueuePri, Boosts.lookup(T.Tag));
91 std::lock_guard<std::mutex> Lock(Mu);
94 Queue.push_back(std::move(T));
95 std::push_heap(Queue.begin(), Queue.end());
104 std::lock_guard<std::mutex> Lock(Mu);
105 for (
Task &T : Tasks) {
108 Queue.push_back(std::move(T));
111 std::make_heap(Queue.begin(), Queue.end());
118 std::lock_guard<std::mutex> Lock(Mu);
119 unsigned &Boost = Boosts[
Tag];
120 bool Increase = NewPriority > Boost;
126 for (
Task &T : Queue)
127 if (
Tag == T.Tag && NewPriority > T.QueuePri) {
128 T.QueuePri = NewPriority;
132 std::make_heap(Queue.begin(), Queue.end());
137 std::optional<double> TimeoutSeconds) {
138 std::unique_lock<std::mutex> Lock(Mu);
140 [&] {
return Queue.empty() && Stat.
Active == 0; });
143void BackgroundQueue::notifyProgress()
const {
144 dlog(
"Queue: {0}/{1} ({2} active). Last idle at {3}", Stat.
Completed,
static void preventThreadStarvationInTests()
void append(std::vector< Task >)
bool blockUntilIdleForTest(std::optional< double > TimeoutSeconds)
void work(std::function< void()> OnIdle=nullptr)
void boost(llvm::StringRef Tag, unsigned NewPriority)
static std::atomic< bool > PreventStarvation
void wait(std::unique_lock< std::mutex > &Lock, std::condition_variable &CV, Deadline D)
Wait once on CV for the specified duration.
Deadline timeoutSeconds(std::optional< double > Seconds)
Makes a deadline from a timeout in seconds. std::nullopt means wait forever.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
A work item on the thread pool's queue.
std::function< void()> Run
llvm::ThreadPriority ThreadPri