00001 /* 00002 * PROPRIETARY INFORMATION. This software is proprietary to 00003 * Side Effects Software Inc., and is not to be reproduced, 00004 * transmitted, or disclosed in any way without written permission. 00005 * 00006 * Produced by: 00007 * Side Effects Software Inc 00008 * 477 Richmond Street West 00009 * Toronto, Ontario 00010 * Canada M5V 3E7 00011 * 416-504-9876 00012 * 00013 * NAME: SYS_AtomicInt.h ( UT Library, C++) 00014 * 00015 * COMMENTS: Thread-safe operations on 32-bit integers 00016 */ 00017 00018 #ifndef __SYS_AtomicInt__ 00019 #define __SYS_AtomicInt__ 00020 00021 #include "SYS_API.h" 00022 #include "SYS_Types.h" 00023 00024 class SYS_API SYS_AtomicInt32 00025 { 00026 public: 00027 explicit SYS_AtomicInt32(int32 value = 0) : myValue(value) {} 00028 00029 /// Note that to use any of these three methods you must 00030 /// #include SYS_AtomicIntImpl. Do *not* include that file 00031 /// in a .h file as it brings in windows.h! 00032 00033 /// Atomically assigns val to myValue, returning the prior value of 00034 /// myValue. 00035 inline int32 exchange(int32 val); 00036 00037 /// Atomically adds val to myValue, returning the prior value of 00038 /// myValue. 00039 inline int32 exchangeAdd(int32 val); 00040 00041 /// Atomically adds val to myValue, returning the new value of myValue. 00042 inline int32 add(int32 val); 00043 00044 /// Atomically set myValue to the maximum of val and myValue. 00045 inline void maximum(int32 val); 00046 00047 void set(int32 val) { myValue = val; } 00048 operator int32() const { return myValue; } 00049 00050 private: 00051 int32 myValue; 00052 00053 private: 00054 // Prohibited operators 00055 SYS_AtomicInt32(const SYS_AtomicInt32 &); 00056 SYS_AtomicInt32 &operator=(const SYS_AtomicInt32 &); 00057 }; 00058 00059 #endif 00060
1.5.9