TAtomicCountWin32.h

Go to the documentation of this file.
00001 // @(#)root/thread:$Id: TAtomicCountWin32.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_TAtomicCountWin32
00013 #define ROOT_TAtomicCountWin32
00014 
00015 //////////////////////////////////////////////////////////////////////////
00016 //                                                                      //
00017 // TAtomicCountWin32                                                    //
00018 //                                                                      //
00019 // Class providing atomic operations on a long. Setting, getting,       //
00020 // incrementing and decrementing are atomic, thread safe, operations.   //
00021 //                                                                      //
00022 // This implementation uses the Win32 InterLocked API for locking.      //
00023 //                                                                      //
00024 // ATTENTION: Don't use this file directly, it is included by           //
00025 //            TAtomicCount.h.                                           //
00026 //                                                                      //
00027 //////////////////////////////////////////////////////////////////////////
00028 
00029 # include "Windows4Root.h"
00030 
00031 class TAtomicCount {
00032 private:
00033    Long_t fCnt;   // counter
00034 
00035    TAtomicCount(const TAtomicCount &);             // not implemented
00036    TAtomicCount &operator=(const TAtomicCount &);  // not implemented
00037 
00038 public:
00039    explicit TAtomicCount(Long_t v) : fCnt(v) { }
00040    void operator++() { InterlockedIncrement(&fCnt); }
00041    Long_t operator--() { return InterlockedDecrement(&fCnt); }
00042    operator long() const { return static_cast<long const volatile &>(fCnt); }
00043    void Set(Long_t v) { fCnt = v; }
00044    Long_t Get() const { return static_cast<long const volatile &>(fCnt); }
00045 };
00046 
00047 #endif

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