Beamlib
3.5.3
This is the Beam C++ class library.
Loading...
Searching...
No Matches
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
* For license see LICENSE.txt at the root of the beamlib source tree.
8
*/
9
#ifndef BAtomic_H
10
#define BAtomic_H 1
11
12
#include <
BTypes.h
>
13
15
template
<
class
Type>
class
BAtomic
{
16
public
:
17
BAtomic
(Type value = 0) : ovalue(value){}
18
19
Type
getValue
()
const
{
20
return
__sync_fetch_and_add(&ovalue, 0);
21
}
22
Type
add
(
long
value){
23
return
__sync_add_and_fetch(&ovalue, value);
24
}
25
Type
operator++
(
int
){
26
return
__sync_fetch_and_add(&ovalue, 1);
27
}
28
Type
operator++
(){
29
return
__sync_add_and_fetch(&ovalue, 1);
30
}
31
Type
operator--
(
int
){
32
return
__sync_fetch_and_add(&ovalue, -1);
33
}
34
Type
operator--
(){
35
return
__sync_add_and_fetch(&ovalue, -1);
36
}
37
operator
Type()
const
{
38
return
getValue
();
39
}
40
private
:
41
mutable
Type ovalue;
42
};
43
44
typedef
BAtomic<BInt32>
BAtomicInt32
;
45
typedef
BAtomic<BInt64>
BAtomicInt64
;
46
typedef
BAtomic<BUInt32>
BAtomicUInt32
;
47
typedef
BAtomic<BUInt64>
BAtomicUInt64
;
48
49
#endif
BAtomicUInt32
BAtomic< BUInt32 > BAtomicUInt32
Definition
BAtomic.h:46
BAtomicInt64
BAtomic< BInt64 > BAtomicInt64
Definition
BAtomic.h:45
BAtomicUInt64
BAtomic< BUInt64 > BAtomicUInt64
Definition
BAtomic.h:47
BAtomicInt32
BAtomic< BInt32 > BAtomicInt32
Definition
BAtomic.h:44
BTypes.h
BAtomic
BAtomic class increments/decrements different integer types.
Definition
BAtomic.h:15
BAtomic::getValue
Type getValue() const
Definition
BAtomic.h:19
BAtomic::BAtomic
BAtomic(Type value=0)
Definition
BAtomic.h:17
BAtomic::operator--
Type operator--()
Definition
BAtomic.h:34
BAtomic::operator--
Type operator--(int)
Definition
BAtomic.h:31
BAtomic::operator++
Type operator++(int)
Definition
BAtomic.h:25
BAtomic::add
Type add(long value)
Definition
BAtomic.h:22
BAtomic::operator++
Type operator++()
Definition
BAtomic.h:28
Generated by
1.12.0