#include <wefts_counter.h>
Inheritance diagram for Wefts::Counter:
This syncronization objects implements a mutex and a condition plus an integer counter. Thraeds synchronizing on this object can just test the value of the integer value, or lock the mutex and change it, or wait for the counter to have reached any value.
This is an object that should usually created by the user, but as the Thread class must use a couple of synchronized counters to do some internal tasks, this class is then published also for final user availability.
Moreover, it's internal strucuture can suggest how to implement similar synchronized objects as strings, structures or user defined classes.
Public Member Functions | |
Counter (int count=0) | |
Initializes the counter to a given value. | |
int | count () |
Retunrs the current value of the counter. | |
void | set (int value) |
Sets the internal counter value without locking or signaling. | |
void | count (int value) |
Sets the count to a given value. | |
void | increment (int amount) |
Increments the value of the counter of the given amount. | |
void | increment () |
Increments the value of the counter of one unit. | |
void | decrement () |
Decrements the value of the counter of one unit. | |
bool | until (int level, double time=0) |
Wait for the counter to reach a certain value. | |
Private Attributes | |
volatile int | m_count |
Internal integer counter. |
|
Initializes the counter to a given value.
|
|
Sets the count to a given value. The object is not locked while the count is assigned, but it is signaled so waiting threads are woken up.
|
|
Retunrs the current value of the counter. The returned value could change before the calling thread has a chance to use it, unless this object is locked. |
|
Decrements the value of the counter of one unit. A signal is also broadcasted so waiting threads are notified. |
|
Increments the value of the counter of one unit. A signal is also broadcasted so waiting threads are notified. |
|
Increments the value of the counter of the given amount. A signal is also broadcasted so waiting threads are notified.
|
|
Sets the internal counter value without locking or signaling. The caller must provide proper lock/signal actions.
|
|
Wait for the counter to reach a certain value.
|
|
Internal integer counter.
|