11#include "llvm/ADT/ScopeExit.h"
12#include "llvm/Support/Threading.h"
13#include "llvm/Support/thread.h"
19#elif defined(__APPLE__)
20#include <sys/resource.h>
30 std::lock_guard<std::mutex> Lock(Mu);
39 std::unique_lock<std::mutex> Lock(Mu);
40 return clangd::wait(Lock, CV, D, [&] {
return Notified; });
46 std::unique_lock<std::mutex> Lock(Mutex);
59 std::unique_lock<std::mutex> Lock(Mutex);
60 SlotsChanged.wait(Lock, [&]() {
return FreeSlots > 0; });
66 std::unique_lock<std::mutex> Lock(Mutex);
70 SlotsChanged.notify_one();
76 std::unique_lock<std::mutex> Lock(Mutex);
78 [&] {
return InFlightTasks == 0; });
82 llvm::unique_function<
void()>
Action) {
84 std::lock_guard<std::mutex> Lock(Mutex);
88 auto CleanupTask = llvm::make_scope_exit([
this]() {
89 std::lock_guard<std::mutex> Lock(Mutex);
90 int NewTasksCnt = --InFlightTasks;
91 if (NewTasksCnt == 0) {
94 TasksReachedZero.notify_one();
99 Cleanup = std::move(CleanupTask)]()
mutable {
100 llvm::set_thread_name(
Name);
108 std::optional<unsigned>(8 << 20),
114 using namespace std::chrono;
117 return steady_clock::now() +
118 duration_cast<steady_clock::duration>(duration<double>(*Seconds));
121void wait(std::unique_lock<std::mutex> &Lock, std::condition_variable &CV,
126 return CV.wait(Lock);
127 CV.wait_until(Lock, D.time());
131 Rep Now = Stopwatch::now().time_since_epoch().count();
132 Rep OldNext = Next.load(std::memory_order_acquire);
137 Rep NewNext = Now + Period;
138 return Next.compare_exchange_strong(OldNext, NewNext,
139 std::memory_order_acq_rel);
llvm::SmallString< 256U > Name
void runAsync(const llvm::Twine &Name, llvm::unique_function< void()> Action)
~AsyncTaskRunner()
Destructor waits for all pending tasks to finish.
A point in time we can wait for.
static Deadline infinity()
bool operator()()
Returns whether the operation should run at this time.
Semaphore(std::size_t MaxLocks)
Records an event whose duration is the lifetime of the Span object.
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++ -*-===//