• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

spl/threading/InterlockCounter.h

00001 /* Ported to SPL, orignal attribution below. */
00002 /* ---------------------------------------------------------------------------
00003    commonc++ - A C++ Common Class Library
00004    Copyright (C) 2005-2009  Mark A Lindner
00005 
00006    Ported from commonc++.
00007 
00008    This library is free software; you can redistribute it and/or
00009    modify it under the terms of the GNU Library General Public
00010    License as published by the Free Software Foundation; either
00011    version 2 of the License, or (at your option) any later version.
00012 
00013    This library is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016    Library General Public License for more details.
00017 
00018    You should have received a copy of the GNU Library General Public
00019    License along with this library; if not, write to the Free
00020    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00021    ---------------------------------------------------------------------------
00022 */
00023 #ifndef _interlockcount_h
00024 #define _interlockcount_h
00025 
00026 #include <spl/types.h>
00027 #include <spl/Debug.h>
00028 
00039 class InterlockCounter
00040 {
00041 private:
00042         volatile int32 _atomic;
00043 
00044 public:
00045 
00050         InterlockCounter(int32 value = 0) throw();
00051 
00053         ~InterlockCounter() throw();
00054 
00056         InterlockCounter(const InterlockCounter& other) throw();
00057 
00059         InterlockCounter& operator =(const InterlockCounter& other) throw();
00060 
00062         int32 operator++() throw();
00063 
00065         int32 operator++(int) throw();
00066 
00068         int32 operator--() throw();
00069 
00071         int32 operator--(int) throw();
00072 
00074         int32 operator+=(int32 delta) throw();
00075 
00077         int32 operator-=(int32 delta) throw();
00078 
00080         int32 operator+(int32 delta) const throw();
00081 
00083         int32 operator-(int32 delta) const throw();
00084 
00086         int32 operator=(int32 value) throw();
00087 
00089         int32 Set(int32 value) throw();
00090 
00092         int32 Swap(int32 value) throw();
00093 
00094         inline bool operator >(int32 i) const
00095         {
00096                 return Get() > i;
00097         }
00098 
00099         inline bool operator >=(int32 i) const
00100         {
00101                 return Get() >= i;
00102         }
00103 
00104         inline bool operator <(int32 i) const
00105         {
00106                 return Get() < i;
00107         }
00108 
00109         inline bool operator <=(int32 i) const
00110         {
00111                 return Get() <= i;
00112         }
00113 
00114         inline bool operator !=(int32 i) const
00115         {
00116                 return Get() != i;
00117         }
00118 
00126         int32 TestAndSet(int32 value, int32 comparand) throw();
00127 
00129         int32 Get() const throw();
00130 
00132         inline operator int32() const throw()
00133         { 
00134                 return Get(); 
00135         }
00136 };
00137 
00138 inline void ValidateType(const InterlockCounter& i)
00139 {
00140 }
00141 
00142 REGISTER_TYPEOF( 458, InterlockCounter );
00143 
00146 #endif