Tkrzw
Public Member Functions | List of all members
tkrzw::WaitCounter Class Referencefinal

Wait counter for monitoring other threads. More...

#include <tkrzw_thread_util.h>

Public Member Functions

 WaitCounter (int32_t initial=0)
 Constructor. More...
 
void Add (int32_t increment=1)
 Adds a value to the counter. More...
 
int32_t Get () const
 Gets the current value of the counter. More...
 
void Done (int32_t decrement=1)
 Decrements a value from the counter and notify if the result value is zero or less. More...
 
bool Wait (double timeout=-1)
 Waits for the counter value to be zero or less. More...
 

Detailed Description

Wait counter for monitoring other threads.

Constructor & Destructor Documentation

◆ WaitCounter()

tkrzw::WaitCounter::WaitCounter ( int32_t  initial = 0)
explicit

Constructor.

Parameters
initialThe initial value of the counter.

Member Function Documentation

◆ Add()

void tkrzw::WaitCounter::Add ( int32_t  increment = 1)

Adds a value to the counter.

Parameters
incrementThe incremental value. Use a nagative for decrement.

◆ Get()

int32_t tkrzw::WaitCounter::Get ( ) const

Gets the current value of the counter.

Returns
The current value of the counter.

◆ Done()

void tkrzw::WaitCounter::Done ( int32_t  decrement = 1)

Decrements a value from the counter and notify if the result value is zero or less.

Parameters
decrementThe decremental value.

◆ Wait()

bool tkrzw::WaitCounter::Wait ( double  timeout = -1)

Waits for the counter value to be zero or less.

Parameters
timeoutThe timeout in seconds to wait. Zero means no wait. Negative means unlimited.
Returns
True if successful or false on timeout.