FIX::atomic_count Class Reference

Atomic count class - consider using interlocked functions. More...

#include <AtomicCount.h>

Public Member Functions

 atomic_count (long v)
long operator++ ()
long operator-- ()
 operator long () const

Private Member Functions

 atomic_count (atomic_count const &)
atomic_countoperator= (atomic_count const &)

Static Private Member Functions

static int atomic_exchange_and_add (int *pw, int dv)

Private Attributes

int value_

Detailed Description

Atomic count class - consider using interlocked functions.

Definition at line 126 of file AtomicCount.h.

Constructor & Destructor Documentation

◆ atomic_count() [1/2]

FIX::atomic_count::atomic_count ( long v)
inlineexplicit

Definition at line 130 of file AtomicCount.h.

130: value_(static_cast<int>(v)) {}

References value_.

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

◆ atomic_count() [2/2]

FIX::atomic_count::atomic_count ( atomic_count const & )
private

References atomic_count().

Member Function Documentation

◆ atomic_exchange_and_add()

int FIX::atomic_count::atomic_exchange_and_add ( int * pw,
int dv )
inlinestaticprivate

Definition at line 156 of file AtomicCount.h.

157 {
158 // int r = *pw;
159 // *pw += dv;
160 // return r;
161
162 int r;
163
164 __asm__ __volatile__
165 (
166 "lock\n\t"
167 "xadd %1, %0":
168 "+m"(*pw), "=r"(r) : // outputs (%0, %1)
169 "1"(dv) : // inputs (%2 == %1)
170 "memory", "cc" // clobbers
171 );
172
173 return r;
174 }

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

◆ operator long()

FIX::atomic_count::operator long ( ) const
inline

Definition at line 142 of file AtomicCount.h.

143 {
144 return atomic_exchange_and_add( &value_, 0 );
145 }
static int atomic_exchange_and_add(int *pw, int dv)

References atomic_exchange_and_add(), and value_.

◆ operator++()

long FIX::atomic_count::operator++ ( )
inline

Definition at line 132 of file AtomicCount.h.

133 {
134 return atomic_exchange_and_add( &value_, 1 ) + 1;
135 }

References atomic_exchange_and_add(), and value_.

◆ operator--()

long FIX::atomic_count::operator-- ( )
inline

Definition at line 137 of file AtomicCount.h.

138 {
139 return atomic_exchange_and_add( &value_, -1 ) - 1;
140 }

References atomic_exchange_and_add(), and value_.

◆ operator=()

atomic_count & FIX::atomic_count::operator= ( atomic_count const & )
private

References atomic_count().

Member Data Documentation

◆ value_

int FIX::atomic_count::value_
mutableprivate

Definition at line 152 of file AtomicCount.h.

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


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

Generated on for QuickFIX by doxygen 1.15.0 written by Dimitri van Heesch, © 1997-2001