ROOT
6.16/01
Reference Guide
core
thread
inc
TAtomicCountGcc.h
Go to the documentation of this file.
1
// @(#)root/thread:$Id$
2
// Author: Fons Rademakers 14/11/06
3
4
/*************************************************************************
5
* Copyright (C) 1995-2006, Rene Brun and Fons Rademakers. *
6
* All rights reserved. *
7
* *
8
* For the licensing terms see $ROOTSYS/LICENSE. *
9
* For the list of contributors see $ROOTSYS/README/CREDITS. *
10
*************************************************************************/
11
12
#ifndef ROOT_TAtomicCountGcc
13
#define ROOT_TAtomicCountGcc
14
15
16
//////////////////////////////////////////////////////////////////////////
17
// //
18
// TAtomicCountGcc //
19
// //
20
// Class providing atomic operations on a long. Setting, getting, //
21
// incrementing and decrementing are atomic, thread safe, operations. //
22
// //
23
// This implementation uses GNU libstdc++ v3 atomic primitives, see //
24
// http://gcc.gnu.org/onlinedocs/porting/Thread-safety.html. //
25
// //
26
// ATTENTION: Don't use this file directly, it is included by //
27
// TAtomicCount.h. //
28
// //
29
//////////////////////////////////////////////////////////////////////////
30
31
#ifndef ROOT_TAtomicCount
32
# error This should be #included only by TAtomicCount.h. Please #include TAtomicCount.h.
33
#endif
//ROOT_TAtomicCount
34
35
#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2) || \
36
(defined(__APPLE_CC__) && __APPLE_CC__ > 5000 && !defined(MAC_OS_X_VERSION_10_6))
37
#include <bits/atomicity.h>
38
#else
39
#include <ext/atomicity.h>
40
#endif
41
42
#include "
Rtypes.h
"
43
44
#if defined(__GLIBCXX__)
// g++ 3.4+
45
46
using
__gnu_cxx::__atomic_add;
47
using
__gnu_cxx::__exchange_and_add;
48
49
#endif
50
51
52
class
TAtomicCount
{
53
private
:
54
mutable
_Atomic_word
fCnt
;
// counter
55
56
TAtomicCount
(
const
TAtomicCount
&);
// not implemented
57
TAtomicCount
&
operator=
(
const
TAtomicCount
&);
// not implemented
58
59
public
:
60
explicit
TAtomicCount
(
Long_t
v
) :
fCnt
(
v
) { }
61
void
operator++
() { __atomic_add(&
fCnt
, 1); }
62
Long_t
operator--
() {
return
__exchange_and_add(&
fCnt
, -1) - 1; }
63
operator
long()
const
{
return
__exchange_and_add(&
fCnt
, 0); }
64
void
Set
(
Long_t
v
) {
65
fCnt
=
v
;
66
#ifdef _GLIBCXX_WRITE_MEM_BARRIER
67
#if !(defined(__INTEL_COMPILER) && defined(__ia64__))
//ICC doesn't support inline asm on IA-64
68
_GLIBCXX_WRITE_MEM_BARRIER;
69
#endif
70
#endif
71
}
72
Long_t
Get
()
const
{
return
__exchange_and_add(&
fCnt
, 0); }
73
};
74
75
#endif
v
SVector< double, 2 > v
Definition:
Dict.h:5
Long_t
long Long_t
Definition:
RtypesCore.h:50
Rtypes.h
TAtomicCount
Definition:
TAtomicCount.h:67
TAtomicCount::TAtomicCount
TAtomicCount(const TAtomicCount &)
TAtomicCount::Get
Long_t Get() const
Definition:
TAtomicCountGcc.h:72
TAtomicCount::operator=
TAtomicCount & operator=(const TAtomicCount &)
TAtomicCount::operator++
void operator++()
Definition:
TAtomicCountGcc.h:61
TAtomicCount::fCnt
Long_t fCnt
Definition:
TAtomicCount.h:69
TAtomicCount::fCnt
_Atomic_word fCnt
Definition:
TAtomicCountGcc.h:54
TAtomicCount::TAtomicCount
TAtomicCount(Long_t v)
Definition:
TAtomicCountGcc.h:60
TAtomicCount::operator--
Long_t operator--()
Definition:
TAtomicCountGcc.h:62
TAtomicCount::Set
void Set(Long_t v)
Definition:
TAtomicCountGcc.h:64