Make it possible to override the synchonization primitives used by the threadpool using macros.

This commit is contained in:
Rasmus Munk Larsen
2023-05-09 19:36:17 +00:00
parent 1321821e86
commit 96c42771d6
6 changed files with 27 additions and 17 deletions

View File

@@ -33,7 +33,7 @@ class Barrier {
eigen_plain_assert(((v + 2) & ~1) != 0);
return; // either count has not dropped to 0, or waiter is not waiting
}
std::unique_lock<std::mutex> l(mu_);
EIGEN_MUTEX_LOCK l(mu_);
eigen_plain_assert(!notified_);
notified_ = true;
cv_.notify_all();
@@ -42,15 +42,15 @@ class Barrier {
void Wait() {
unsigned int v = state_.fetch_or(1, std::memory_order_acq_rel);
if ((v >> 1) == 0) return;
std::unique_lock<std::mutex> l(mu_);
EIGEN_MUTEX_LOCK l(mu_);
while (!notified_) {
cv_.wait(l);
}
}
private:
std::mutex mu_;
std::condition_variable cv_;
EIGEN_MUTEX mu_;
EIGEN_CONDVAR cv_;
std::atomic<unsigned int> state_; // low bit is waiter flag
bool notified_;
};