Parallel.h: Adopt std::atomic::wait when llvm-project requires C++20
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
@aganea @nga888
Optimization opportunity after https://github.com/llvm/llvm-project/pull/189196
`llvm/include/llvm/Support/Parallel.h` can be optimized to eliminate mutex+condition_variable once llvm-project requires C++20
```cpp
class Latch {
std::atomic Count;
public:
explicit Latch(uint32_t Count = 0) : Count(Count) {}
~Latch() { assert(Count.load(std::memory_order_relaxed) == 0); }
void inc() { Count.fetch_add(1, std::memory_order_relaxed); }
void dec() {
if (Count.fetch_sub(1, std::memory_order_acq_rel) == 1)
Count.notify_all();
}
uint32_t getCount() const { return Count.load(std::memory_order_acquire); }
void sync() const {
uint32_t val;
while ((val = Count.load(std::memory_order_acquire)) != 0)
Count.wait(val, std::memory_order_relaxed);
}
};
```
We cannot use std::latch (https://en.cppreference.com/w/cpp/thread/latch.html) because of `inc()`.
Contributor guide
Assessment
This issue has not been assessed yet.