TAtomicCount.h

Go to the documentation of this file.
00001 // @(#)root/thread:$Id: TAtomicCount.h 20882 2007-11-19 11:31:26Z rdm $
00002 // Author: Fons Rademakers   14/11/06
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #ifndef ROOT_TAtomicCount
00013 #define ROOT_TAtomicCount
00014 
00015 
00016 //////////////////////////////////////////////////////////////////////////
00017 //                                                                      //
00018 // TAtomicCount                                                         //
00019 //                                                                      //
00020 // Class providing atomic operations on a long. Setting, getting,       //
00021 // incrementing and decrementing are atomic, thread safe, operations.   //
00022 //                                                                      //
00023 //  TAtomicCount a(n);                                                  //
00024 //                                                                      //
00025 //    (n is convertible to long)                                        //
00026 //                                                                      //
00027 //    Effects: Constructs an TAtomicCount with an initial value of n.   //
00028 //                                                                      //
00029 //  long(a);                                                            //
00030 //                                                                      //
00031 //    Returns: (long) the current value of a.                           //
00032 //                                                                      //
00033 //  ++a;                                                                //
00034 //                                                                      //
00035 //    Effects: Atomically increments the value of a.                    //
00036 //    Returns: nothing.                                                 //
00037 //                                                                      //
00038 //  --a;                                                                //
00039 //                                                                      //
00040 //    Effects: Atomically decrements the value of a.                    //
00041 //    Returns: (long) zero if the new value of a is zero,               //
00042 //             unspecified non-zero value otherwise                     //
00043 //             (usually the new value).                                 //
00044 //                                                                      //
00045 //  a.Set(n);                                                           //
00046 //                                                                      //
00047 //    Effects: Set a to the value n.                                    //
00048 //    Returns: nothing.                                                 //
00049 //                                                                      //
00050 //  a.Get();                                                            //
00051 //                                                                      //
00052 //    Returns: (long) the current value of a.                           //
00053 //                                                                      //
00054 //                                                                      //
00055 //////////////////////////////////////////////////////////////////////////
00056 
00057 #ifndef ROOT_Rtypes
00058 #include "Rtypes.h"
00059 #endif
00060 #ifndef ROOT_RConfigure
00061 #include "RConfigure.h"
00062 #endif
00063 
00064 #if (defined(__GLIBCPP__) || defined(__GLIBCXX__)) && !defined(__CINT__)
00065 #include "TAtomicCountGcc.h"
00066 #elif defined(_WIN32) && !defined(__CINT__)
00067 #include "TAtomicCountWin32.h"
00068 #elif defined(R__HAS_PTHREAD) && !defined(__CINT__)
00069 #include "TAtomicCountPthread.h"
00070 #else
00071 class TAtomicCount {
00072 private:
00073    Long_t  fCnt;   // counter
00074 
00075    TAtomicCount(const TAtomicCount &);             // not implemented
00076    TAtomicCount &operator=(const TAtomicCount &);  // not implemented
00077 
00078 public:
00079    explicit TAtomicCount(Long_t v) : fCnt(v) { }
00080    void operator++() { ++fCnt; }
00081    Long_t operator--() { return --fCnt; }
00082    operator long() const { return fCnt; }
00083    void Set(Long_t v) { fCnt = v; }
00084    Long_t Get() const { return fCnt; }
00085 };
00086 #endif
00087 
00088 #endif

Generated on Tue Jul 5 14:11:59 2011 for ROOT_528-00b_version by  doxygen 1.5.1