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