Eigen::Barrier Class Reference
+ Inheritance diagram for Eigen::Barrier:

Public Member Functions

 Barrier (unsigned int count)
 
void Notify ()
 
void Wait ()
 
 ~Barrier ()
 

Private Attributes

EIGEN_CONDVAR cv_
 
EIGEN_MUTEX mu_
 
bool notified_
 
std::atomic< unsigned int > state_
 

Detailed Description

Definition at line 20 of file Barrier.h.

Constructor & Destructor Documentation

◆ Barrier()

Eigen::Barrier::Barrier ( unsigned int  count)
inline

Definition at line 22 of file Barrier.h.

22  : state_(count << 1), notified_(false) {
23  eigen_plain_assert(((count << 1) >> 1) == count);
24  }
#define eigen_plain_assert(condition)
Definition: Assert.h:156
bool notified_
Definition: Barrier.h:55
std::atomic< unsigned int > state_
Definition: Barrier.h:54

◆ ~Barrier()

Eigen::Barrier::~Barrier ( )
inline

Definition at line 25 of file Barrier.h.

25 { eigen_plain_assert((state_ >> 1) == 0); }

Member Function Documentation

◆ Notify()

void Eigen::Barrier::Notify ( )
inline

Definition at line 27 of file Barrier.h.

27  {
28  unsigned int v = state_.fetch_sub(2, std::memory_order_acq_rel) - 2;
29  if (v != 1) {
30  // Clear the lowest bit (waiter flag) and check that the original state
31  // value was not zero. If it was zero, it means that notify was called
32  // more times than the original count.
33  eigen_plain_assert(((v + 2) & ~1) != 0);
34  return; // either count has not dropped to 0, or waiter is not waiting
35  }
38  notified_ = true;
39  cv_.notify_all();
40  }
Array< int, Dynamic, 1 > v
#define EIGEN_MUTEX_LOCK
Definition: ThreadPool:58
EIGEN_CONDVAR cv_
Definition: Barrier.h:53
EIGEN_MUTEX mu_
Definition: Barrier.h:52

◆ Wait()

void Eigen::Barrier::Wait ( )
inline

Definition at line 42 of file Barrier.h.

42  {
43  unsigned int v = state_.fetch_or(1, std::memory_order_acq_rel);
44  if ((v >> 1) == 0) return;
46  while (!notified_) {
47  cv_.wait(l);
48  }
49  }

Member Data Documentation

◆ cv_

EIGEN_CONDVAR Eigen::Barrier::cv_
private

Definition at line 53 of file Barrier.h.

◆ mu_

EIGEN_MUTEX Eigen::Barrier::mu_
private

Definition at line 52 of file Barrier.h.

◆ notified_

bool Eigen::Barrier::notified_
private

Definition at line 55 of file Barrier.h.

◆ state_

std::atomic<unsigned int> Eigen::Barrier::state_
private

Definition at line 54 of file Barrier.h.


The documentation for this class was generated from the following file: