Logo ROOT   6.10/09
Reference Guide
TWin32AtomicCount.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_TWin32AtomicCount
13 #define ROOT_TWin32AtomicCount
14 
15 //////////////////////////////////////////////////////////////////////////
16 // //
17 // TWin32AtomicCount //
18 // //
19 // Class providing atomic operations on a long. Setting, getting, //
20 // incrementing and decrementing are atomic, thread safe, operations. //
21 // //
22 // This implementation uses the Win32 InterLocked API for locking. //
23 // //
24 //////////////////////////////////////////////////////////////////////////
25 
26 #ifndef ROOT_TAtomicCount
27 #error "Do not use TWin32AtomicCount.h directly. #include \"TAtomicCount.h\" instead."
28 #endif // ROOT_TAtomicCount
29 
30 # include "Windows4Root.h"
31 
32 class TAtomicCount {
33 private:
34  Long_t fCnt; // counter
35 
36  TAtomicCount(const TAtomicCount &); // not implemented
37  TAtomicCount &operator=(const TAtomicCount &); // not implemented
38 
39 public:
40  explicit TAtomicCount(Long_t v) : fCnt(v) { }
41  void operator++() { InterlockedIncrement(&fCnt); }
42  Long_t operator--() { return InterlockedDecrement(&fCnt); }
43  operator long() const { return static_cast<long const volatile &>(fCnt); }
44  void Set(Long_t v) { fCnt = v; }
45  Long_t Get() const { return static_cast<long const volatile &>(fCnt); }
46 };
47 
48 #endif
Long_t operator--()
Long_t Get() const
SVector< double, 2 > v
Definition: Dict.h:5
void Set(Long_t v)
TAtomicCount(Long_t v)
long Long_t
Definition: RtypesCore.h:50
TAtomicCount & operator=(const TAtomicCount &)
TAtomicCount(const TAtomicCount &)