Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   Related Pages  

Wefts::Counter Class Reference

Syncrhonizable counter. More...

#include <wefts_counter.h>

Inheritance diagram for Wefts::Counter:

Inheritance graph
[legend]
Collaboration diagram for Wefts::Counter:

Collaboration graph
[legend]
List of all members.

Public Methods

 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.


Detailed Description

Syncrhonizable 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.

Note:
Counter is derived from FastCondition, this means that the mutex used by counter is not reentrant. It is this way as the mutex is thought just to lock access to very small section of code where the internal integer counter is updated.


Constructor & Destructor Documentation

Wefts::Counter::Counter int    count = 0 [inline]
 

Initializes the counter to a given value.

Parameters:
count  the initial count of the internal counter (if not given defaults to 0)


Member Function Documentation

void Wefts::Counter::count int    value [inline]
 

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.

Parameters:
value  the new value to be set.

int Wefts::Counter::count   [inline]
 

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.

void Wefts::Counter::decrement   [inline]
 

Decrements the value of the counter of one unit.

A signal is also broadcasted so waiting threads are notified.

void Wefts::Counter::increment   [inline]
 

Increments the value of the counter of one unit.

A signal is also broadcasted so waiting threads are notified.

void Wefts::Counter::increment int    amount [inline]
 

Increments the value of the counter of the given amount.

A signal is also broadcasted so waiting threads are notified.

Parameters:
amount  the amount to be added to the current count.

void Wefts::Counter::set int    value [inline]
 

Sets the internal counter value without locking or signaling.

The caller must provide proper lock/signal actions.

Parameters:
value  the new value to be set.

bool Wefts::Counter::until int    level,
double    time = 0
[inline]
 

Wait for the counter to reach a certain value.

Parameters:
level  the value that the counter must match before continue.
time  seconds to wait for the condition to be reached (or 0 forever).
Returns:
true if condition is matched false on timeout or interrupt


Member Data Documentation

volatile int Wefts::Counter::m_count [private]
 

Internal integer counter.


The documentation for this class was generated from the following file:
Generated on Tue Aug 5 18:09:03 2003 for Wefts by doxygen1.2.18