Wait counter for monitoring other threads.
More...
#include <tkrzw_thread_util.h>
|
| 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...
|
|
Wait counter for monitoring other threads.
◆ WaitCounter()
tkrzw::WaitCounter::WaitCounter |
( |
int32_t |
initial = 0 | ) |
|
|
explicit |
Constructor.
- Parameters
-
initial | The initial value of the counter. |
◆ Add()
void tkrzw::WaitCounter::Add |
( |
int32_t |
increment = 1 | ) |
|
Adds a value to the counter.
- Parameters
-
increment | The 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
-
decrement | The decremental value. |
◆ Wait()
bool tkrzw::WaitCounter::Wait |
( |
double |
timeout = -1 | ) |
|
Waits for the counter value to be zero or less.
- Parameters
-
timeout | The timeout in seconds to wait. Zero means no wait. Negative means unlimited. |
- Returns
- True if successful or false on timeout.