Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | List of all members
dart::ThreadBarrier Class Reference

#include <thread_barrier.h>

Public Member Functions

 ThreadBarrier (intptr_t num_threads, intptr_t initial=0)
 
bool TryEnter ()
 
void Sync ()
 
void Release ()
 

Detailed Description

Definition at line 47 of file thread_barrier.h.

Constructor & Destructor Documentation

◆ ThreadBarrier()

dart::ThreadBarrier::ThreadBarrier ( intptr_t  num_threads,
intptr_t  initial = 0 
)
inlineexplicit

Definition at line 49 of file thread_barrier.h.

50 : ref_count_(num_threads),
51 monitor_(),
52 participating_(initial),
53 remaining_(initial),
54 generation_(0) {}

Member Function Documentation

◆ Release()

void dart::ThreadBarrier::Release ( )
inline

Definition at line 83 of file thread_barrier.h.

83 {
84 intptr_t old = ref_count_.fetch_sub(1, std::memory_order_acq_rel);
85 ASSERT(old > 0);
86 if (old == 1) {
87 delete this;
88 }
89 }
#define ASSERT(E)

◆ Sync()

void dart::ThreadBarrier::Sync ( )
inline

Definition at line 66 of file thread_barrier.h.

66 {
67 MonitorLocker ml(&monitor_);
68 const intptr_t g = generation_;
69 remaining_--;
70 if (remaining_ == 0) {
71 // I'm last, advance to the next generation and wake the others.
72 generation_++;
73 remaining_ = participating_;
74 ml.NotifyAll();
75 } else {
76 // Waiting for others.
77 while (g == generation_) {
78 ml.Wait();
79 }
80 }
81 }

◆ TryEnter()

bool dart::ThreadBarrier::TryEnter ( )
inline

Definition at line 56 of file thread_barrier.h.

56 {
57 MonitorLocker ml(&monitor_);
58 if (generation_ != 0) {
59 return false;
60 }
61 remaining_++;
62 participating_++;
63 return true;
64 }

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