Fawkes API
Fawkes Development Version
|
A barrier is a synchronization tool which blocks until a given number of threads have reached the barrier. More...
#include <>>
Public Member Functions | |
InterruptibleBarrier (unsigned int count) | |
Constructor. More... | |
InterruptibleBarrier (Mutex *mutex, unsigned int count) | |
Constructor with custom mutex. More... | |
virtual | ~InterruptibleBarrier () |
Destructor. More... | |
bool | wait (unsigned int timeout_sec, unsigned int timeout_nanosec) |
Wait for other threads. More... | |
virtual void | wait () |
Wait for other threads. More... | |
void | interrupt () throw () |
Interrupt the barrier. More... | |
void | reset () throw () |
Clears the barrier. More... | |
RefPtr< ThreadList > | passed_threads () |
Get a list of threads that passed the barrier. More... | |
bool | no_threads_in_wait () |
Checks if there are no more threads in the wait() function. More... | |
![]() | |
Barrier (unsigned int count) | |
Constructor. More... | |
virtual | ~Barrier () |
Destructor. More... | |
unsigned int | count () |
Get number of threads this barrier will wait for. More... | |
Additional Inherited Members | |
![]() | |
Barrier () | |
Protected Constructor. More... | |
![]() | |
unsigned int | _count |
Number of threads that are expected to wait for the barrier. More... | |
A barrier is a synchronization tool which blocks until a given number of threads have reached the barrier.
This particular implementations allows for giving a timeout after which the waiting is aborted.
For general information when a barrier is useful see the Barrier class.
Additionally to the general barrier features the InterruptibleBarrier::wait() can be given a timeout after which the waiting is aborted. Since the POSIX standard does not provide a timed wait for barriers this implementation uses a Mutex and WaitCondition internally to achieve the desired result.
Definition at line 38 of file interruptible_barrier.h.
fawkes::InterruptibleBarrier::InterruptibleBarrier | ( | unsigned int | count | ) |
Constructor.
count | the number of threads to wait for |
Definition at line 90 of file interruptible_barrier.cpp.
References fawkes::Barrier::_count, and fawkes::Barrier::count().
Referenced by InterruptibleBarrier(), and wait().
fawkes::InterruptibleBarrier::InterruptibleBarrier | ( | Mutex * | mutex, |
unsigned int | count | ||
) |
Constructor with custom mutex.
Use this constructor only if you really know what you are doing. This constructor allows to pass a mutex that is used internally for the barrier. Note that in this case it is your duty to lock the mutex before the wait() and unlock afterwards! It combines features of a barrier and a wait condition.
mutex | Mutex to use |
count | the number of threads to wait for |
Definition at line 115 of file interruptible_barrier.cpp.
References fawkes::Barrier::_count, fawkes::Barrier::Barrier(), fawkes::Barrier::count(), and InterruptibleBarrier().
|
virtual |
Destructor.
Definition at line 179 of file interruptible_barrier.cpp.
void fawkes::InterruptibleBarrier::interrupt | ( | ) | ||
throw | ( | |||
) |
Interrupt the barrier.
This will cause all threads currently waiting on the barrier to throw an exception and no further thread will wait. You have to call reset() the before you use this barrier the next time.
Definition at line 205 of file interruptible_barrier.cpp.
Referenced by fawkes::FawkesMainThread::set_mainloop_thread(), and wait().
bool fawkes::InterruptibleBarrier::no_threads_in_wait | ( | ) |
Checks if there are no more threads in the wait() function.
This method is used to prevent the destruction of the barrier while there are threads in wait().
Definition at line 327 of file interruptible_barrier.cpp.
Referenced by fawkes::ThreadList::erase(), fawkes::ThreadList::set_maintain_barrier(), and wait().
RefPtr< ThreadList > fawkes::InterruptibleBarrier::passed_threads | ( | ) |
Get a list of threads that passed the barrier.
The list contains the threads that passed the barrier. With some book keeping outside of the barrier you can determine which threads you expected at the barrier but did not pass it.
Definition at line 192 of file interruptible_barrier.cpp.
Referenced by wait(), and fawkes::ThreadList::wakeup_and_wait().
void fawkes::InterruptibleBarrier::reset | ( | ) | ||
throw | ( | |||
) |
Clears the barrier.
Call this method when you want to use the barrier the next time after an interrupt or timeout occured. Make sure all threads that should have passed the barrier the last time did pass it.
Definition at line 220 of file interruptible_barrier.cpp.
References fawkes::Barrier::_count.
Referenced by wait().
bool fawkes::InterruptibleBarrier::wait | ( | unsigned int | timeout_sec, |
unsigned int | timeout_nanosec | ||
) |
Wait for other threads.
This method will block until as many threads have called wait as you have given count to the constructor. Note that if the barrier is interrupted or times out you need to call reset() to get the barrier into a re-usable state. It is your duty to make sure that all threads using the barrier are in a cohesive state.
timeout_sec | relative timeout in seconds, added to timeout_nanosec |
timeout_nanosec | timeout in nanoseconds |
InterruptedException | thrown if the barrier was forcefully interrupted by calling interrupt(). |
Definition at line 245 of file interruptible_barrier.cpp.
References fawkes::Barrier::_count, fawkes::Thread::current_thread(), fawkes::Exception::print_trace(), and fawkes::Barrier::wait().
Referenced by fawkes::FawkesMainThread::loop(), and fawkes::ThreadList::wakeup_and_wait().
|
inlinevirtual |
Wait for other threads.
This method will block until as many threads have called wait as you have given count to the constructor.
Reimplemented from fawkes::Barrier.
Definition at line 46 of file interruptible_barrier.h.
References interrupt(), InterruptibleBarrier(), no_threads_in_wait(), passed_threads(), reset(), and wait().
Referenced by wait().