UCommon
atomic.h
Go to the documentation of this file.
1 // Copyright (C) 2006-2014 David Sugar, Tycho Softworks.
2 //
3 // This file is part of GNU uCommon C++.
4 //
5 // GNU uCommon C++ is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published
7 // by the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // GNU uCommon C++ is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with GNU uCommon C++. If not, see <http://www.gnu.org/licenses/>.
17 
25 #ifndef _UCOMMON_ATOMIC_H_
26 #define _UCOMMON_ATOMIC_H_
27 
28 #ifndef _UCOMMON_CONFIG_H_
29 #include <ucommon/platform.h>
30 #endif
31 
32 namespace ucommon {
33 
42 class __EXPORT atomic
43 {
44 public:
48  static const bool simulated;
49 
55  class __EXPORT counter
56  {
57  private:
58  volatile long value;
59 
60  public:
61  counter(long initial = 0);
62 
63  long operator++();
64  long operator--();
65  long operator+=(long offset);
66  long operator-=(long offset);
67 
68  inline operator long()
69  {return (long)(value);}
70 
71  inline long operator*()
72  {return value;}
73  };
74 
80  class __EXPORT spinlock
81  {
82  private:
83  volatile long value;
84 
85  public:
89  spinlock();
90 
96  bool acquire(void);
97 
101  void release(void);
102  };
103 };
104 
105 } // namespace ucommon
106 
107 #endif
static const bool simulated
Set to true if atomics have to be simulated with mutexes.
Definition: atomic.h:48
Common namespace for all ucommon objects.
void release(SharedAccess &object)
Convenience function to unlock shared object through it's protocol.
Definition: access.h:260
Various miscellaneous platform specific headers and defines.
Atomic counter class.
Definition: atomic.h:55
Atomic spinlock class.
Definition: atomic.h:80
Generic atomic class for referencing atomic objects and static functions.
Definition: atomic.h:42
void acquire(mutex_t &mutex)
Convenience function to acquire a mutex.
Definition: thread.h:1947