PAtomicInteger Class Reference

This class implements an integer that can be atomically incremented and decremented in a thread-safe manner. More...

`#include <critsec.h>`

Inheritance diagram for PAtomicInteger:

## Public Types

typedef PAtomicBase::IntegerType | IntegerType

## Public Member Functions

| PAtomicInteger (IntegerType value=0)
| Create a PAtomicInteger with the specified initial value. More...
__inline | operator IntegerType () const
__inline PAtomicInteger & | operator= (IntegerType value)
| Assign a value to the atomic integer. More...
void | SetValue (IntegerType value)
| Set the value of the atomic integer. More...
__inline bool | IsZero () const
| Test if an atomic integer has a zero value. More...
__inline bool | operator! () const
| Test if atomic integer has a non-zero value. More...
IntegerType | operator++ ()
| atomically pre-increment the integer value More...
IntegerType | operator++ (int)
| atomically post-increment the integer value More...
IntegerType | operator-- ()
| atomically pre-decrement the integer value More...
IntegerType | operator-- (int)
| atomically post-decrement the integer value More...

## Friends

__inline ostream & | operator<< (ostream &strm, const PAtomicInteger &i)

## Detailed Description

This class implements an integer that can be atomically incremented and decremented in a thread-safe manner.

On Windows, the integer is of type long and this class is implemented using InterlockedIncrement and InterlockedDecrement integer is of type long.

On Unix systems with GNU std++ support for __exchange_and_add, the integer is of type _Atomic_word (normally int).

On Solaris atomic_add_32_nv is used.

On all other systems, this class is implemented using PCriticalSection and the integer is of type int.

## Member Typedef Documentation

## IntegerType

typedef PAtomicBase::IntegerType PAtomicInteger::IntegerType

## Constructor & Destructor Documentation

## PAtomicInteger()

PAtomicInteger::PAtomicInteger | ( | IntegerType | value = `0` | ) |

inline explicit

Create a PAtomicInteger with the specified initial value.

Parameters

  value | initial value

## Member Function Documentation

## IsZero()

__inline bool PAtomicInteger::IsZero | ( |  | ) | const

inline

Test if an atomic integer has a zero value.

Note that this, is a non-atomic test - use the return value of the operator++() or operator--() tests to perform atomic operations

Returns
  true if the integer has a value of zero.

## operator IntegerType()

__inline PAtomicInteger::operator IntegerType | ( |  | ) | const

inline

Returns
  Returns the value of the atomic integer

## operator!()

__inline bool PAtomicInteger::operator! | ( |  | ) | const

inline

Test if atomic integer has a non-zero value.

## operator++() [1/2]

__inline PAtomicInteger::IntegerType PAtomicInteger::operator++ | ( |  | ) |

atomically pre-increment the integer value

Returns
  Returns the value of the integer after the increment

References PAtomicBase::m_value.

Referenced by PAtomicBoolean::TestAndSet().

## operator++() [2/2]

__inline PAtomicInteger::IntegerType PAtomicInteger::operator++ | ( | int |  | ) |

atomically post-increment the integer value

Returns
  Returns the value of the integer before the increment

References PAtomicBase::m_value.

## operator--() [1/2]

__inline PAtomicInteger::IntegerType PAtomicInteger::operator-- | ( |  | ) |

atomically pre-decrement the integer value

Returns
  Returns the value of the integer after the decrement

References PAtomicBase::m_value.

Referenced by PAtomicBoolean::TestAndSet().

## operator--() [2/2]

__inline PAtomicInteger::IntegerType PAtomicInteger::operator-- | ( | int |  | ) |

atomically post-decrement the integer value

Returns
  Returns the value of the integer before the decrement

References PAtomicBase::m_value.

## operator=()

__inline PAtomicInteger& PAtomicInteger::operator= | ( | IntegerType | value | ) |

inline

Assign a value to the atomic integer.

## SetValue()

void PAtomicInteger::SetValue | ( | IntegerType | value | ) |

inline

Set the value of the atomic integer.

Parameters

  value | value to set

## Friends And Related Function Documentation

## operator<<

__inline ostream& operator<< | ( | ostream & | strm,
|  | const PAtomicInteger & | i
| ) |  |

friend

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

- critsec.h