Bayonne2 / Common C++ 2 Framework
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Attributes
AtomicCounter Class Reference

The AtomicCounter class offers thread-safe manipulation of an integer counter. More...

#include <thread.h>

Collaboration diagram for AtomicCounter:
Collaboration graph

Public Member Functions

 AtomicCounter ()
 Initialize an atomic counter to 0. More...
 AtomicCounter (int value)
 Initialize an atomic counter to a known value. More...
 ~AtomicCounter ()
int operator++ (void)
int operator-- (void)
int operator+= (int change)
int operator-= (int change)
int operator+ (int change)
int operator- (int change)
int operator= (int value)
bool operator! (void)
 operator int ()

Private Attributes

volatile int counter
pthread_mutex_t _mutex

Detailed Description

The AtomicCounter class offers thread-safe manipulation of an integer counter.

These are commonly used for building thread-safe "reference" counters for C++ classes. The AtomicCounter depends on the platforms support for "atomic" integer operations, and can alternately substitute a "mutex" if no atomic support exists.

Sean Cavanaugh atomic counter operation.

Definition at line 535 of file thread.h.

Constructor & Destructor Documentation

AtomicCounter::AtomicCounter ( )

Initialize an atomic counter to 0.

AtomicCounter::AtomicCounter ( int  value)

Initialize an atomic counter to a known value.

valueinitial value.
AtomicCounter::~AtomicCounter ( )

Member Function Documentation

AtomicCounter::operator int ( )
bool AtomicCounter::operator! ( void  )
int AtomicCounter::operator+ ( int  change)
int AtomicCounter::operator++ ( void  )
int AtomicCounter::operator+= ( int  change)
int AtomicCounter::operator- ( int  change)
int AtomicCounter::operator-- ( void  )
int AtomicCounter::operator-= ( int  change)
int AtomicCounter::operator= ( int  value)

Field Documentation

pthread_mutex_t AtomicCounter::_mutex

Definition at line 550 of file thread.h.

volatile int AtomicCounter::counter

Definition at line 549 of file thread.h.

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