UCommon
ucommon/atomic.h
Go to the documentation of this file.
00001 // Copyright (C) 2006-2010 David Sugar, Tycho Softworks.
00002 //
00003 // This file is part of GNU uCommon C++.
00004 //
00005 // GNU uCommon C++ is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU Lesser General Public License as published 
00007 // by the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // GNU uCommon C++ is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public License
00016 // along with GNU uCommon C++.  If not, see <http://www.gnu.org/licenses/>.
00017 
00025 #ifndef _UCOMMON_ATOMIC_H_
00026 #define _UCOMMON_ATOMIC_H_
00027 
00028 #ifndef _UCOMMON_CONFIG_H_
00029 #include <ucommon/platform.h>
00030 #endif
00031 
00032 NAMESPACE_UCOMMON
00033 
00042 class __EXPORT atomic
00043 {
00044 public:
00048     static const bool simulated;
00049 
00055     class __EXPORT counter
00056     {
00057     private:
00058         volatile long value;
00059     
00060     public:
00061         counter(long initial = 0);
00062 
00063         long operator++();
00064         long operator--();
00065         long operator+=(long offset);
00066         long operator-=(long offset);
00067 
00068         inline operator long()
00069             {return (long)(value);};
00070 
00071         inline long operator*()
00072             {return value;};
00073     };
00074 
00080     class __EXPORT spinlock
00081     {
00082     private:
00083         volatile long value;
00084 
00085     public:
00089         spinlock();
00090 
00096         bool acquire(void);
00097 
00101         void release(void);
00102     };
00103 };
00104 
00105 END_NAMESPACE
00106 
00107 #endif