ROOT  6.06/09
Reference Guide
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 #ifndef ROOT_Rtypes
58 #include "Rtypes.h"
59 #endif
60 #ifndef ROOT_RConfigure
61 #include "RConfigure.h"
62 #endif
63 
64 #if (defined(__GLIBCPP__) || defined(__GLIBCXX__)) && !defined(__CINT__)
65 #include "TAtomicCountGcc.h"
66 #elif defined(_WIN32) && !defined(__CINT__)
67 #include "TAtomicCountWin32.h"
68 #elif defined(R__HAS_PTHREAD) && !defined(__CINT__)
69 #include "TAtomicCountPthread.h"
70 #else
71 class TAtomicCount {
72 private:
73  Long_t fCnt; // counter
74 
75  TAtomicCount(const TAtomicCount &); // not implemented
76  TAtomicCount &operator=(const TAtomicCount &); // not implemented
77 
78 public:
79  explicit TAtomicCount(Long_t v) : fCnt(v) { }
80  void operator++() { ++fCnt; }
81  Long_t operator--() { return --fCnt; }
82  operator long() const { return fCnt; }
83  void Set(Long_t v) { fCnt = v; }
84  Long_t Get() const { return fCnt; }
85 };
86 #endif
87 
88 #endif
Long_t operator--()
Definition: TAtomicCount.h:81
SVector< double, 2 > v
Definition: Dict.h:5
void Set(Long_t v)
Definition: TAtomicCount.h:83
TAtomicCount(Long_t v)
Definition: TAtomicCount.h:79
long Long_t
Definition: RtypesCore.h:50
TAtomicCount & operator=(const TAtomicCount &)
Long_t Get() const
Definition: TAtomicCount.h:84
TAtomicCount(const TAtomicCount &)
void operator++()
Definition: TAtomicCount.h:80