Fork Vasum on GitHub Official Vasum Wiki on Tizen.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
utils::Latch Class Reference

A synchronization aid that allows one thread to wait until an operation being performed in other thread completes. More...

#include <latch.hpp>

Public Member Functions

 Latch ()
 
void set ()
 Sets an event occurred. More...
 
void wait ()
 Waits for a single occurrence of event. More...
 
bool wait (const unsigned int timeoutMs)
 Waits for a single occurrence of event with timeout. More...
 
void waitForN (const unsigned int n)
 Waits for
occurrences of event. More...
 
bool waitForN (const unsigned int n, const unsigned int timeoutMs)
 Waits for
occurrences of event with timeout. More...
 
bool empty ()
 Check if there are no pending events. More...
 

Private Attributes

std::mutex mMutex
 
std::condition_variable mCondition
 
unsigned int mCount
 

Detailed Description

A synchronization aid that allows one thread to wait until an operation being performed in other thread completes.

It has a similar function as std::promise<void> but allows multiple calls to set.

Constructor & Destructor Documentation

utils::Latch::Latch ( )

Member Function Documentation

bool utils::Latch::empty ( )

Check if there are no pending events.

void utils::Latch::set ( )

Sets an event occurred.

void utils::Latch::wait ( )

Waits for a single occurrence of event.

bool utils::Latch::wait ( const unsigned int  timeoutMs)

Waits for a single occurrence of event with timeout.

Parameters
timeoutMstimeout in ms to wait for
Returns
false on timeout
void utils::Latch::waitForN ( const unsigned int  n)

Waits for
occurrences of event.

Parameters
nnumber of occurrences to wait for
bool utils::Latch::waitForN ( const unsigned int  n,
const unsigned int  timeoutMs 
)

Waits for
occurrences of event with timeout.

Parameters
nnumber of occurrences to wait for
timeoutMstimeout in ms to wait for
Returns
false on timeout

Member Data Documentation

std::condition_variable utils::Latch::mCondition
private
unsigned int utils::Latch::mCount
private
std::mutex utils::Latch::mMutex
private

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