|
||||
File indexing completed on 2024-11-15 09:56:49
0001 // @(#)root/thread:$Id$ 0002 // Author: Fons Rademakers 14/11/06 0003 0004 /************************************************************************* 0005 * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers. * 0006 * All rights reserved. * 0007 * * 0008 * For the licensing terms see $ROOTSYS/LICENSE. * 0009 * For the list of contributors see $ROOTSYS/README/CREDITS. * 0010 *************************************************************************/ 0011 0012 #ifndef ROOT_TAtomicCount 0013 #define ROOT_TAtomicCount 0014 0015 0016 ////////////////////////////////////////////////////////////////////////// 0017 // // 0018 // TAtomicCount // 0019 // // 0020 // Class providing atomic operations on a long. Setting, getting, // 0021 // incrementing and decrementing are atomic, thread safe, operations. // 0022 // // 0023 // TAtomicCount a(n); // 0024 // // 0025 // (n is convertible to long) // 0026 // // 0027 // Effects: Constructs an TAtomicCount with an initial value of n. // 0028 // // 0029 // long(a); // 0030 // // 0031 // Returns: (long) the current value of a. // 0032 // // 0033 // ++a; // 0034 // // 0035 // Effects: Atomically increments the value of a. // 0036 // Returns: nothing. // 0037 // // 0038 // --a; // 0039 // // 0040 // Effects: Atomically decrements the value of a. // 0041 // Returns: (long) zero if the new value of a is zero, // 0042 // unspecified non-zero value otherwise // 0043 // (usually the new value). // 0044 // // 0045 // a.Set(n); // 0046 // // 0047 // Effects: Set a to the value n. // 0048 // Returns: nothing. // 0049 // // 0050 // a.Get(); // 0051 // // 0052 // Returns: (long) the current value of a. // 0053 // // 0054 // // 0055 ////////////////////////////////////////////////////////////////////////// 0056 0057 #include "RtypesCore.h" 0058 #include "RConfigure.h" 0059 0060 #if (defined(__GLIBCPP__) || defined(__GLIBCXX__)) && !defined(__CINT__) 0061 #include "TAtomicCountGcc.h" 0062 #elif defined(_WIN32) && !defined(__CINT__) 0063 #include "TWin32AtomicCount.h" 0064 #elif defined(R__HAS_PTHREAD) && !defined(__CINT__) 0065 #include "TAtomicCountPthread.h" 0066 #else 0067 class TAtomicCount { 0068 private: 0069 Long_t fCnt; // counter 0070 0071 TAtomicCount(const TAtomicCount &) = delete; 0072 TAtomicCount &operator=(const TAtomicCount &) = delete; 0073 0074 public: 0075 explicit TAtomicCount(Long_t v) : fCnt(v) { } 0076 void operator++() { ++fCnt; } 0077 Long_t operator--() { return --fCnt; } 0078 operator long() const { return fCnt; } 0079 void Set(Long_t v) { fCnt = v; } 0080 Long_t Get() const { return fCnt; } 0081 }; 0082 #endif 0083 0084 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |