CppCMS
atomic_counter.h
1 //
2 // Copyright (C) 2009-2012 Artyom Beilis (Tonkikh)
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //
8 #ifndef BOOSTER_ATOMIC_COUNT_H
9 #define BOOSTER_ATOMIC_COUNT_H
10 
11 #include <booster/config.h>
12 
13 
18 namespace booster {
19 
32 
33  class BOOSTER_API atomic_counter {
34  public:
38  explicit atomic_counter( long v );
39  ~atomic_counter();
40 
44  long operator++()
45  {
46  return inc();
47  }
51  long operator--()
52  {
53  return dec();
54  }
58  operator long() const
59  {
60  return get();
61  }
62  private:
63  long inc();
64  long dec();
65  long get() const;
66 
68  atomic_counter & operator=(atomic_counter const &);
69 
70  mutable union {
71  int i;
72  unsigned ui;
73  long l;
74  unsigned long ul;
75  long long ll;
76  unsigned long long ull;
77  } value_;
78  // Is actually used for platforms without lock
79  // it would not be used when atomic operations
80  // available
81  void *mutex_;
82  };
83 
84 } // booster
85 
86 #endif
87 
88 
long operator++()
Definition: atomic_counter.h:44
long operator--()
Definition: atomic_counter.h:51
Booster library namespace. The library that implements Boost Like API in ABI backward compatible way...
Definition: application.h:23
Atomic counter is a class that allows perform counting in thread safe way.
Definition: atomic_counter.h:33