Archon::Utilities::Atomic Struct Reference

Atomic integer operations. More...

#include <archon/util/atomic.H>

Collaboration diagram for Archon::Utilities::Atomic:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Atomic ()
 Atomic (int w)
 operator int () const
Atomicoperator= (int w)
Atomicoperator++ ()
int operator++ (int)
Atomicoperator-- ()
int operator-- (int)
Atomicoperator+= (int w)
Atomicoperator-= (int w)
int get () const
 Read the value of this integer object atomically.
void set (int w)
 Assign a new value to this integer object atomically.
void inc ()
 Increment the value of this integer object atomically.
void dec ()
 Decrement the value of this integer object atomically.
void add (int w)
 Add to the value of this integer object atomically.
void sub (int w)
 Subtract from the value of this integer object atomically.
bool decAndZeroTest ()
 Decrement the value of this integer object and test if the result is zero.
int fetchAndAdd (int w)
 Add to the value of this integer object and return its original value.
bool testAndSet (int t, int w)
 Assign a new value to this integer object but only if it has a certain original value.

Detailed Description

Atomic integer operations.

Useful for reference counting etc..

Inspired by the following implementations of similar functionality:

Currently a fast implementations is only available on Intel 486 and above with GCC.

If you need to port this class to other platforms, then please consult these other implementations.

Todo:
Find a way to discriminate between i386 and i486+.
Probably through autoconf. See http://cvs.gnome.org/viewcvs/glib/configure.in?view=auto

Definition at line 54 of file atomic.H.


Member Function Documentation

void Archon::Utilities::Atomic::add int  w  )  [inline]
 

Add to the value of this integer object atomically.

Parameters:
w The value to add.

Definition at line 281 of file atomic.H.

Referenced by operator+=(), and operator-=().

bool Archon::Utilities::Atomic::decAndZeroTest  )  [inline]
 

Decrement the value of this integer object and test if the result is zero.

The increment and the test operation is performed as one single atomic operation.

Returns:
True iff the result was zero.

Definition at line 293 of file atomic.H.

int Archon::Utilities::Atomic::fetchAndAdd int  w  )  [inline]
 

Add to the value of this integer object and return its original value.

The read and the add operation is performed as one single atomic operation.

Parameters:
w The value to add.
Returns:
The original value.

Definition at line 299 of file atomic.H.

Referenced by operator++(), and operator--().

int Archon::Utilities::Atomic::get  )  const [inline]
 

Read the value of this integer object atomically.

Returns:
The value of this integer object as it was when read.

Definition at line 257 of file atomic.H.

Referenced by operator int().

Archon::Utilities::Atomic::operator int  )  const [inline]
 

See also:
get

Definition at line 62 of file atomic.H.

References get().

int Archon::Utilities::Atomic::operator++ int   )  [inline]
 

See also:
fetchAndAdd

Definition at line 77 of file atomic.H.

References fetchAndAdd().

Atomic& Archon::Utilities::Atomic::operator++  )  [inline]
 

See also:
inc

Definition at line 72 of file atomic.H.

References inc().

Atomic& Archon::Utilities::Atomic::operator+= int  w  )  [inline]
 

See also:
add

Definition at line 92 of file atomic.H.

References add().

int Archon::Utilities::Atomic::operator-- int   )  [inline]
 

See also:
fetchAndAdd

Definition at line 87 of file atomic.H.

References fetchAndAdd().

Atomic& Archon::Utilities::Atomic::operator--  )  [inline]
 

See also:
dec

Definition at line 82 of file atomic.H.

References dec().

Atomic& Archon::Utilities::Atomic::operator-= int  w  )  [inline]
 

See also:
sub

Definition at line 97 of file atomic.H.

References add().

Atomic& Archon::Utilities::Atomic::operator= int  w  )  [inline]
 

See also:
set

Definition at line 67 of file atomic.H.

References set().

void Archon::Utilities::Atomic::set int  w  )  [inline]
 

Assign a new value to this integer object atomically.

Parameters:
w The value to assign.

Definition at line 263 of file atomic.H.

Referenced by Atomic(), and operator=().

void Archon::Utilities::Atomic::sub int  w  )  [inline]
 

Subtract from the value of this integer object atomically.

Parameters:
w The value to subtract.

Definition at line 287 of file atomic.H.

bool Archon::Utilities::Atomic::testAndSet int  t,
int  w
[inline]
 

Assign a new value to this integer object but only if it has a certain original value.

The test and the assignment operation (if applicable) is performed as one single atomic operation.

Parameters:
t The required original value.
w The new value to be assigned.
Returns:
True iff the assignment was done (ie. the test was successful.)

Definition at line 307 of file atomic.H.


The documentation for this struct was generated from the following file:
Generated on Sun Jul 30 22:57:16 2006 for Archon by  doxygen 1.4.4