ROOT
6.14/05
Reference Guide
core
thread
inc
TAtomicCount.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_TAtomicCount
13
#define ROOT_TAtomicCount
14
15
16
//////////////////////////////////////////////////////////////////////////
17
// //
18
// TAtomicCount //
19
// //
20
// Class providing atomic operations on a long. Setting, getting, //
21
// incrementing and decrementing are atomic, thread safe, operations. //
22
// //
23
// TAtomicCount a(n); //
24
// //
25
// (n is convertible to long) //
26
// //
27
// Effects: Constructs an TAtomicCount with an initial value of n. //
28
// //
29
// long(a); //
30
// //
31
// Returns: (long) the current value of a. //
32
// //
33
// ++a; //
34
// //
35
// Effects: Atomically increments the value of a. //
36
// Returns: nothing. //
37
// //
38
// --a; //
39
// //
40
// Effects: Atomically decrements the value of a. //
41
// Returns: (long) zero if the new value of a is zero, //
42
// unspecified non-zero value otherwise //
43
// (usually the new value). //
44
// //
45
// a.Set(n); //
46
// //
47
// Effects: Set a to the value n. //
48
// Returns: nothing. //
49
// //
50
// a.Get(); //
51
// //
52
// Returns: (long) the current value of a. //
53
// //
54
// //
55
//////////////////////////////////////////////////////////////////////////
56
57
#include "
Rtypes.h
"
58
#include "RConfigure.h"
59
60
#if (defined(__GLIBCPP__) || defined(__GLIBCXX__)) && !defined(__CINT__)
61
#include "
TAtomicCountGcc.h
"
62
#elif defined(_WIN32) && !defined(__CINT__)
63
#include "
TWin32AtomicCount.h
"
64
#elif defined(R__HAS_PTHREAD) && !defined(__CINT__)
65
#include "
TAtomicCountPthread.h
"
66
#else
67
class
TAtomicCount
{
68
private
:
69
Long_t
fCnt
;
// counter
70
71
TAtomicCount
(
const
TAtomicCount
&);
// not implemented
72
TAtomicCount
&
operator=
(
const
TAtomicCount
&);
// not implemented
73
74
public
:
75
explicit
TAtomicCount
(
Long_t
v
) : fCnt(v) { }
76
void
operator++
() { ++
fCnt
; }
77
Long_t
operator--
() {
return
--
fCnt
; }
78
operator
long()
const
{
return
fCnt
; }
79
void
Set
(
Long_t
v
) { fCnt =
v
; }
80
Long_t
Get
()
const
{
return
fCnt
; }
81
};
82
#endif
83
84
#endif
TAtomicCount::operator--
Long_t operator--()
Definition:
TAtomicCount.h:77
TAtomicCount::Get
Long_t Get() const
Definition:
TAtomicCount.h:80
Rtypes.h
TAtomicCountPthread.h
TWin32AtomicCount.h
TAtomicCount
Definition:
TAtomicCount.h:67
v
SVector< double, 2 > v
Definition:
Dict.h:5
TAtomicCount::Set
void Set(Long_t v)
Definition:
TAtomicCount.h:79
TAtomicCount::TAtomicCount
TAtomicCount(Long_t v)
Definition:
TAtomicCount.h:75
Long_t
long Long_t
Definition:
RtypesCore.h:50
TAtomicCountGcc.h
TAtomicCount::fCnt
Long_t fCnt
Definition:
TAtomicCount.h:69
TAtomicCount::operator=
TAtomicCount & operator=(const TAtomicCount &)
TAtomicCount::TAtomicCount
TAtomicCount(const TAtomicCount &)
TAtomicCount::operator++
void operator++()
Definition:
TAtomicCount.h:76