Beam-lib  2.16.3
This is the Beam C++ class library.
BAtomic.h
Go to the documentation of this file.
1 /*******************************************************************************
2  * BAtomic.h BAtomic Atomic variables
3  * T.Barnaby, BEAM Ltd, 2010-10-07
4  * Copyright (c) 2012 All Right Reserved, Beam Ltd, http://www.beam.ltd.uk
5  *******************************************************************************
6  */
7 #ifndef BAtomic_H
8 #define BAtomic_H 1
9 
10 #include <BTypes.h>
11 
13 template <class Type> class BAtomic {
14 public:
15  BAtomic(Type value = 0) : ovalue(value){}
16 
17  Type getValue() const {
18  return __sync_fetch_and_add(&ovalue, 0);
19  }
20  Type add(long value){
21  return __sync_add_and_fetch(&ovalue, value);
22  }
23  Type operator++(int){
24  return __sync_fetch_and_add(&ovalue, 1);
25  }
26  Type operator++(){
27  return __sync_add_and_fetch(&ovalue, 1);
28  }
29  Type operator--(int){
30  return __sync_fetch_and_add(&ovalue, -1);
31  }
32  Type operator--(){
33  return __sync_add_and_fetch(&ovalue, -1);
34  }
35  operator Type() const {
36  return getValue();
37  }
38 private:
39  mutable Type ovalue;
40 };
41 
46 
47 #endif
Type operator--(int)
Definition: BAtomic.h:29
Type operator--()
Definition: BAtomic.h:32
Type getValue() const
Definition: BAtomic.h:17
BAtomic< BInt32 > BAtomicInt32
Definition: BAtomic.h:42
BAtomic< BUInt32 > BAtomicUInt32
Definition: BAtomic.h:44
BAtomic< BInt64 > BAtomicInt64
Definition: BAtomic.h:43
Type operator++(int)
Definition: BAtomic.h:23
BAtomic(Type value=0)
Definition: BAtomic.h:15
BAtomic< BUInt64 > BAtomicUInt64
Definition: BAtomic.h:45
Type operator++()
Definition: BAtomic.h:26
Type add(long value)
Definition: BAtomic.h:20
BAtomic class.
Definition: BAtomic.h:13