AtomicCounter.h
1 //##################################################################################################
2 //
3 // Ceetron 3D 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  #if (CEE_GCC_VER >= 40200) && (defined(__x86_64__) || defined(__i386__))
24  #define CEE_HAVE_GCC_ATOMICS
25  #define CEE_ATOMIC_COUNTER_CLASS_EXISTS
26  #elif (CEE_GCC_VER >= 40300)
27  #define CEE_HAVE_GCC_ATOMICS
28  #define CEE_ATOMIC_COUNTER_CLASS_EXISTS
29  #endif
30 #endif
31 #ifdef CEE_IOS // Disable for all compilers and architectures for Apple iOS
32  #undef CEE_ATOMIC_COUNTER_CLASS_EXISTS
33  #ifndef CEE_WORKAROUND_TO_COMPILE_ON_SYSTEMS_WITHOUT_ATOMICS
34  #define CEE_WORKAROUND_TO_COMPILE_ON_SYSTEMS_WITHOUT_ATOMICS
35  #endif
36 #endif
37 
38 #if defined(CEE_ATOMIC_COUNTER_CLASS_EXISTS)
39 
40 namespace cee {
41 
42 class CEE_CORE_EXPORT AtomicCounter
43 {
44 public:
45  explicit AtomicCounter(int initialValue);
46  ~AtomicCounter();
47 
48  operator int () const;
49  void setCount(int count);
50 
51  void add(int count);
52 
53  int operator ++ (); // prefix
54  int operator ++ (int); // postfix
55 
56  int operator -- (); // prefix
57  int operator -- (int); // postfix
58 
59 private:
60 
61  CEE_DISALLOW_COPY_AND_ASSIGN(AtomicCounter);
62 
63 #ifdef WIN32
64  typedef volatile long ImplType;
65 #elif defined(CEE_IOS) || defined(CEE_OSX)
66  typedef int32_t ImplType;
67 #else
68  typedef int ImplType;
69 #endif
70 
71  ImplType m_counter;
72 };
73 
74 
75 }
76 
77 #endif
Namespace cee contains all functionality and structures under the Core component. ...
Definition: AppLogging.cpp:20