Bites
A small library of miscellaneous C++ codes.
 All Classes Namespaces Functions Friends Pages
Static Protected Member Functions | List of all members
bites::MutexedCounter< T > Class Template Reference

#include <MutexedCounter.hpp>

Static Protected Member Functions

static int incrCount ()
 
static int decrCount ()
 

Detailed Description

template<typename T>
class bites::MutexedCounter< T >

Thread-safe class-wide counter. You can use it, for example, as base class for your bites::Thread implementation to track class-wide counts:

class MyThread : public bites::Thread,
public bites::MutexedCounter<MyThread>
{
private:
void run () {
std::cout << incrCount() << std::endl;
// Do useful stuff.
std::cout << decrCount() << std::endl;
}
};

Class-specific counting is implemented using "Curiously recurring template pattern" (CRTP): http://en.wikipedia.org/wiki/Curiously_recurring_template_pattern

Member Function Documentation

template<typename T >
static int bites::MutexedCounter< T >::incrCount ( )
inlinestaticprotected

Thread-safely increment the count.

template<typename T >
static int bites::MutexedCounter< T >::decrCount ( )
inlinestaticprotected

Thread-safely decrement the count.


The documentation for this class was generated from the following file: