rpa::mutex_count_base Class Reference

Does the actual counting for the template class 'thread_count'. More...

#include <synchro.h>

Inheritance diagram for rpa::mutex_count_base:

rpa::mutex_count< Mutex > List of all members.

Public Member Functions

 mutex_count_base ()
 ~mutex_count_base ()
 The counters are checked to be sure that the mutex is properly unlocked.
void tst_lock (void)
void tst_unlock (void)
 The internal counter is incremented BEFORE the mutex is unlocked.
void tst_trylock (void)
 Note that the counter is incremented AFTER the mutex is locked.

Private Member Functions

bool dump (void) const
 Displays internal information for debugging purpose.
void check (void) const
 Checks the mutex invariant.

Private Attributes

size_t lockNb
 Counts the number of times 'lock()' was called.
size_t unlockNb
 Counts the number of times 'unlock()' was called.
size_t trylockNb
 'trylockNb' is incremented only when the 'trylock' is successful.

Detailed Description

Does the actual counting for the template class 'thread_count'.

This encapsulate a mutex in order to count the number of times it is un-/try/-locked. It also checks the consistency of these counters. The counters are changed only when the base mutex is locked. We check at runtime a very strong relation between these three counters : NbLock + NbSuccessfulTrylock = NbUnlock


Constructor & Destructor Documentation

rpa::mutex_count_base::mutex_count_base (  ) 

rpa::mutex_count_base::~mutex_count_base (  ) 

The counters are checked to be sure that the mutex is properly unlocked.


Member Function Documentation

void rpa::mutex_count_base::check ( void   )  const [private]

Checks the mutex invariant.

Theoretically, we should not need any memory barrier between reads and writes to these counters, because they are properly protected by a mutex.

bool rpa::mutex_count_base::dump ( void   )  const [private]

Displays internal information for debugging purpose.

This wrapper around a mutex provides a new class that still has the requested interfaces for mutexes. The three mandatory methods have all their calls counted, for statistics and for checking consistency : It computes on-the-run an invariant.

void rpa::mutex_count_base::tst_lock ( void   ) 

Beware that the invariant of the mutex can be checked only when the mutex is locked, otherwise there may be a race condition. Also, the internal counters can be incremented only when the base mutex os locked, for the same reason.

void rpa::mutex_count_base::tst_trylock ( void   ) 

Note that the counter is incremented AFTER the mutex is locked.

void rpa::mutex_count_base::tst_unlock ( void   ) 

The internal counter is incremented BEFORE the mutex is unlocked.


Member Data Documentation

size_t rpa::mutex_count_base::lockNb [private]

Counts the number of times 'lock()' was called.

size_t rpa::mutex_count_base::trylockNb [private]

'trylockNb' is incremented only when the 'trylock' is successful.

size_t rpa::mutex_count_base::unlockNb [private]

Counts the number of times 'unlock()' was called.


The documentation for this class was generated from the following files:
Generated on Tue Sep 25 10:20:38 2007 for rpa by  doxygen 1.4.7