Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
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 123 of file AtomicCount.h.

Constructor & Destructor Documentation

◆ atomic_count() [1/2]

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

Definition at line 127 of file AtomicCount.h.

Referenced by operator long().

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

◆ atomic_count() [2/2]

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

Member Function Documentation

◆ atomic_exchange_and_add()

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

Definition at line 153 of file AtomicCount.h.

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

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

◆ operator long()

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

Definition at line 139 of file AtomicCount.h.

References atomic_count(), atomic_exchange_and_add(), operator=(), and value_.

140  {
141  return atomic_exchange_and_add( &value_, 0 );
142  }
static int atomic_exchange_and_add(int *pw, int dv)
Definition: AtomicCount.h:153

◆ operator++()

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

Definition at line 129 of file AtomicCount.h.

References atomic_exchange_and_add(), and value_.

130  {
131  return atomic_exchange_and_add( &value_, 1 ) + 1;
132  }
static int atomic_exchange_and_add(int *pw, int dv)
Definition: AtomicCount.h:153

◆ operator--()

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

Definition at line 134 of file AtomicCount.h.

References atomic_exchange_and_add(), and value_.

135  {
136  return atomic_exchange_and_add( &value_, -1 ) - 1;
137  }
static int atomic_exchange_and_add(int *pw, int dv)
Definition: AtomicCount.h:153

◆ operator=()

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

Referenced by operator long().

Member Data Documentation

◆ value_

int FIX::atomic_count::value_
mutableprivate

Definition at line 149 of file AtomicCount.h.

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


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

Generated on Sun Apr 15 2018 21:44:05 for QuickFIX by doxygen 1.8.13 written by Dimitri van Heesch, © 1997-2001