AtomicCounter.h
1 //##################################################################################################
2 //
3 // Ceetron Desktop Components
4 // Component: Core
5 //
6 // --------------------------------------------------------------------------------------------
7 // Copyright (C) 2015, Ceetron AS
8 // This is UNPUBLISHED PROPRIETARY SOURCE CODE of Ceetron AS. The contents of this file may
9 // not be disclosed to third parties, copied or duplicated in any form, in whole or in part,
10 // without the prior written permission of Ceetron AS.
11 //##################################################################################################
12 
13 #pragma once
14 
15 #include "Base.h"
16 
17 #ifdef WIN32
18  #define CEE_ATOMIC_COUNTER_CLASS_EXISTS
19 #elif defined(CEE_OSX)
20  #include <libkern/OSAtomic.h>
21  #define CEE_ATOMIC_COUNTER_CLASS_EXISTS
22 #elif defined __GNUC__
23  #define CEE_HAVE_GCC_ATOMICS
24  #define CEE_ATOMIC_COUNTER_CLASS_EXISTS
25 #endif
26 #ifdef CEE_IOS // Disable for all compilers and architectures for Apple iOS
27  #undef CEE_ATOMIC_COUNTER_CLASS_EXISTS
28  #ifndef CEE_WORKAROUND_TO_COMPILE_ON_SYSTEMS_WITHOUT_ATOMICS
29  #define CEE_WORKAROUND_TO_COMPILE_ON_SYSTEMS_WITHOUT_ATOMICS
30  #endif
31 #endif
32 
33 #if defined(CEE_ATOMIC_COUNTER_CLASS_EXISTS)
34 
35 namespace cee {
36 
37 class CEE_CORE_EXPORT AtomicCounter
38 {
39 public:
40  explicit AtomicCounter(int initialValue);
41  ~AtomicCounter();
42 
43  operator int () const;
44  void setCount(int count);
45 
46  void add(int count);
47 
48  int operator ++ (); // prefix
49  int operator ++ (int); // postfix
50 
51  int operator -- (); // prefix
52  int operator -- (int); // postfix
53 
54 private:
55 
56  CEE_DISALLOW_COPY_AND_ASSIGN(AtomicCounter);
57 
58 #ifdef WIN32
59  typedef volatile long ImplType;
60 #elif defined(CEE_IOS) || defined(CEE_OSX)
61  typedef int32_t ImplType;
62 #else
63  typedef int ImplType;
64 #endif
65 
66  ImplType m_counter;
67 };
68 
69 
70 }
71 
72 #endif
Namespace cee contains all functionality and structures under the Core component. ...
Definition: AppAssert.cpp:18