AtomicCount.h
Go to the documentation of this file.
1 /* -*- C++ -*- */
2 
3 /****************************************************************************
4 ** Copyright (c) 2001-2014
5 **
6 ** This file is part of the QuickFIX FIX Engine
7 **
8 ** This file may be distributed under the terms of the quickfixengine.org
9 ** license as defined by quickfixengine.org and appearing in the file
10 ** LICENSE included in the packaging of this file.
11 **
12 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
13 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
14 **
15 ** See http://www.quickfixengine.org/LICENSE for licensing information.
16 **
17 ** Contact ask@quickfixengine.org if any conditions of this licensing are
18 ** not clear to you.
19 **
20 ****************************************************************************/
21 
22 #ifndef ATOMIC_COUNT
23 #define ATOMIC_COUNT
24 
25 #include "Mutex.h"
26 
27 namespace FIX
28 {
30 
31 #ifdef ENABLE_BOOST_ATOMIC_COUNT
32 
33 #include <boost/smart_ptr/detail/atomic_count.hpp>
34 typedef boost::detail::atomic_count atomic_count;
35 
36 #elif _MSC_VER
37 
38  //atomic counter based on interlocked functions for Win32
39  class atomic_count
40  {
41  public:
42  explicit atomic_count( long v ): m_counter( v )
43  {
44  }
45 
46  long operator++()
47  {
48  return ::InterlockedIncrement( &m_counter );
49  }
50 
51  long operator--()
52  {
53  return ::InterlockedDecrement( &m_counter );
54  }
55 
56  operator long() const
57  {
58  return static_cast<long const volatile &>( m_counter );
59  }
60 
61  private:
62 
63  atomic_count( atomic_count const & );
64  atomic_count & operator=( atomic_count const & );
65 
66  long volatile m_counter;
67  };
68 
69 #else
70  // general purpose atomic counter using mutexes
71  class atomic_count
72  {
73  public:
74  explicit atomic_count( long v ): m_counter( v )
75  {
76  }
77 
78  long operator++()
79  {
80  Locker _lock(m_mutex);
81  return ++m_counter;
82  }
83 
84  long operator--()
85  {
86  Locker _lock(m_mutex);
87  return --m_counter;
88  }
89 
90  operator long() const
91  {
92  return static_cast<long const volatile &>( m_counter );
93  }
94 
95  private:
96 
97  atomic_count( atomic_count const & );
98  atomic_count & operator=( atomic_count const & );
99 
101  long m_counter;
102  };
103 
104 #endif
105 
106 }
107 
108 #endif
109 
atomic_count(long v)
Definition: AtomicCount.h:74
Definition: Acceptor.cpp:34
Locks/Unlocks a mutex using RAII.
Definition: Mutex.h:95
Portable implementation of a mutex.
Definition: Mutex.h:30
atomic_count & operator=(atomic_count const &)

Generated on Thu Sep 5 2019 11:07:58 for QuickFIX by doxygen 1.8.13 written by Dimitri van Heesch, © 1997-2001