atomic_unsafe.h

Go to the documentation of this file.
00001 
00003 
00004 //
00005 // Copyright (c) 2006-2007 University of Southern California
00006 // Rob Peters <rjpeters at usc dot edu>
00007 //
00008 // created: Thu Aug 10 16:56:03 2006
00009 // commit: $Id: atomic_unsafe.h 10065 2007-04-12 05:54:56Z rjpeters $
00010 // $HeadURL: file:///lab/rjpeters/svnrepo/code/trunk/groovx/src/rutz/atomic_unsafe.h $
00011 //
00012 // --------------------------------------------------------------------
00013 //
00014 // This file is part of GroovX.
00015 //   [http://www.klab.caltech.edu/rjpeters/groovx/]
00016 //
00017 // GroovX is free software; you can redistribute it and/or modify it
00018 // under the terms of the GNU General Public License as published by
00019 // the Free Software Foundation; either version 2 of the License, or
00020 // (at your option) any later version.
00021 //
00022 // GroovX is distributed in the hope that it will be useful, but
00023 // WITHOUT ANY WARRANTY; without even the implied warranty of
00024 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00025 // General Public License for more details.
00026 //
00027 // You should have received a copy of the GNU General Public License
00028 // along with GroovX; if not, write to the Free Software Foundation,
00029 // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00030 //
00032 
00033 #ifndef GROOVX_RUTZ_ATOMIC_UNSAFE_H_UTC20070412044712_DEFINED
00034 #define GROOVX_RUTZ_ATOMIC_UNSAFE_H_UTC20070412044712_DEFINED
00035 
00036 #include <limits>
00037 
00038 namespace rutz
00039 {
00040 
00042 class unsafe_atomic_int
00043 {
00044 private:
00045   int x;
00046 
00047   unsafe_atomic_int(const unsafe_atomic_int&);
00048   unsafe_atomic_int& operator=(const unsafe_atomic_int&);
00049 
00050 public:
00052   unsafe_atomic_int() : x(0) {}
00053 
00055   static int max_value() { return std::numeric_limits<int>::max(); }
00056 
00058   int atomic_get() const
00059   { return x; }
00060 
00062   void atomic_set(int v)
00063   { x = v; }
00064 
00066   void atomic_add(int i)
00067   { x += i; }
00068 
00070   void atomic_sub(int i)
00071   { x -= i; }
00072 
00074   bool atomic_sub_test_zero(int i)
00075   { return bool((x -= i) == 0); }
00076 
00078   void atomic_incr()
00079   { ++x; }
00080 
00082   void atomic_decr()
00083   { --x; }
00084 
00086   bool atomic_decr_test_zero()
00087   { return bool(--x == 0); }
00088 
00090   bool atomic_incr_test_zero()
00091   { return bool(++x == 0); }
00092 
00094   int atomic_add_return(int i)
00095   { return (x += i); }
00096 
00098   int atomic_sub_return(int i)
00099   { return (x -= i); }
00100 
00102   int atomic_incr_return()
00103   { return ++x; }
00104 
00106   int atomic_decr_return()
00107   { return --x; }
00108 };
00109 
00110 } // end namespace rutz
00111 
00112 // ######################################################################
00113 /* So things look consistent in everyone's emacs... */
00114 /* Local Variables: */
00115 /* mode: c++ */
00116 /* indent-tabs-mode: nil */
00117 /* End: */
00118 
00119 static const char __attribute__((used)) vcid_groovx_rutz_atomic_unsafe_h_utc20070412044712[] = "$Id: atomic_unsafe.h 10065 2007-04-12 05:54:56Z rjpeters $ $HeadURL: file:
00120 #endif // !GROOVX_RUTZ_ATOMIC_UNSAFE_H_UTC20070412044712DEFINED

The software described here is Copyright (c) 1998-2005, Rob Peters.
This page was generated Wed Dec 3 06:49:40 2008 by Doxygen version 1.5.5.