libcommonc++  0.7
AtomicCounter.h++
Go to the documentation of this file.
1 /* ---------------------------------------------------------------------------
2  commonc++ - A C++ Common Class Library
3  Copyright (C) 2005-2014 Mark A Lindner
4 
5  This file is part of commonc++.
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public
18  License along with this library; if not, write to the Free
19  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  ---------------------------------------------------------------------------
21 */
22 
23 #ifndef __ccxx_AtomicCounter_hxx
24 #define __ccxx_AtomicCounter_hxx
25 
26 #include <commonc++/Common.h++>
27 #include <commonc++/Mutex.h++>
28 
29 namespace ccxx {
30 
37 {
38  public:
39 
45  AtomicCounter(int32_t value = 0);
46 
48  ~AtomicCounter();
49 
51  AtomicCounter(const AtomicCounter& other);
52 
54  AtomicCounter& operator=(const AtomicCounter& other);
55 
57  int32_t operator++();
58 
60  int32_t operator++(int);
61 
63  int32_t operator--();
64 
66  int32_t operator--(int);
67 
69  int32_t operator+=(int32_t delta);
70 
72  int32_t operator-=(int32_t delta);
73 
75  int32_t operator+(int32_t delta) const;
76 
78  int32_t operator-(int32_t delta) const;
79 
81  int32_t operator=(int32_t value);
82 
84  int32_t set(int32_t value);
85 
87  int32_t swap(int32_t value);
88 
97  int32_t testAndSet(int32_t value, int32_t comparand);
98 
100  int32_t get() const;
101 
103  inline operator int32_t() const
104  { return(get()); }
105 
106  private:
107 
108  mutable int32_t _atomic;
109 };
110 
111 } // namespace ccxx
112 
113 #endif // __ccxx_AtomicCounter_hxx
const TimeSpan operator-(const TimeSpan &s1, const TimeSpan &s2)
Definition: TimeSpan.c++:386
void swap(ScopedPtr< T > &a, ScopedPtr< T > &b)
Swap two ScopedPtr values.
Definition: ScopedPtr.h++:133
const TimeSpan operator+(const TimeSpan &s1, const TimeSpan &s2)
Definition: TimeSpan.c++:362
An integer counter whose value is modified in an atomic fashion.
Definition: AtomicCounter.h++:36
#define COMMONCPP_API
Definition: Common.h++:126
Definition: AllocationMap.c++:25