Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 "RtypesCore.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
68private:
69 Long_t fCnt; // counter
70
71 TAtomicCount(const TAtomicCount &) = delete;
73
74public:
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
long
long Long_t
Definition RtypesCore.h:54
Long_t Get() const
void operator++()
TAtomicCount(const TAtomicCount &)=delete
TAtomicCount(Long_t v)
Long_t operator--()
TAtomicCount & operator=(const TAtomicCount &)=delete
void Set(Long_t v)