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 #include "SYS_MemoryOrder.h" 00024 00025 class SYS_API SYS_AtomicInt32 00026 { 00027 public: 00028 explicit SYS_AtomicInt32(int32 value = 0) : myValue(value) {} 00029 00030 /// Note that to use any of these three methods you must 00031 /// #include SYS_AtomicIntImpl. Do *not* include that file 00032 /// in a .h file as it brings in windows.h! 00033 00034 /// Atomically assigns val to myValue, returning the prior value of 00035 /// myValue. 00036 inline int32 exchange(int32 val); 00037 00038 /// Atomically adds val to myValue, returning the prior value of 00039 /// myValue. 00040 inline int32 exchangeAdd(int32 val); 00041 00042 /// Atomically adds val to myValue, returning the new value of myValue. 00043 inline int32 add(int32 val); 00044 00045 /// Atomically set myValue to the maximum of val and myValue. 00046 inline void maximum(int32 val); 00047 00048 /// Atomically compares (myValue == expected), and if true, replaces 00049 /// myValue with desired. Returns prior myValue. 00050 inline int32 compare_swap(int32 expected, int32 desired); 00051 00052 /// @pre The supplied order must be one of [RELAXED, RELEASE, SEQ_CST]. 00053 inline void store(int32 val, 00054 SYS_MemoryOrder order = SYS_MEMORY_ORDER_SEQ_CST); 00055 00056 /// @pre The supplied order must be one of [RELAXED, CONSUME, ACQUIRE, 00057 /// SEQ_CST]. 00058 inline int32 load(SYS_MemoryOrder order = SYS_MEMORY_ORDER_SEQ_CST) 00059 const; 00060 /// Atomically retrieve value. Same as calling load(). 00061 operator int32() const; 00062 00063 private: 00064 int32 myValue; 00065 00066 private: 00067 // Prohibited operators 00068 SYS_AtomicInt32(const SYS_AtomicInt32 &); 00069 SYS_AtomicInt32 &operator=(const SYS_AtomicInt32 &); 00070 }; 00071 00072 #endif 00073
1.5.9