$search
00001 #ifndef BOOST_DETAIL_ATOMIC_INTERLOCKED_HPP 00002 #define BOOST_DETAIL_ATOMIC_INTERLOCKED_HPP 00003 00004 // Copyright (c) 2009 Helge Bahmann 00005 // 00006 // Distributed under the Boost Software License, Version 1.0. 00007 // See accompanying file LICENSE_1_0.txt or copy at 00008 // http://www.boost.org/LICENSE_1_0.txt) 00009 00010 #include <boost/detail/interlocked.hpp> 00011 00012 #define BOOST_ATOMIC_CHAR_LOCK_FREE 2 00013 #define BOOST_ATOMIC_SHORT_LOCK_FREE 2 00014 #define BOOST_ATOMIC_INT_LOCK_FREE 2 00015 #define BOOST_ATOMIC_LONG_LOCK_FREE (sizeof(long) <= 4 ? 2 : 0) 00016 #define BOOST_ATOMIC_LLONG_LOCK_FREE (sizeof(long long) <= 4 ? 2 : 0) 00017 #define BOOST_ATOMIC_ADDRESS_LOCK_FREE (sizeof(void *) <= 4 ? 2 : 0) 00018 #define BOOST_ATOMIC_BOOL_LOCK_FREE 2 00019 00020 namespace boost { 00021 namespace detail { 00022 namespace atomic { 00023 00024 static inline void 00025 x86_full_fence(void) 00026 { 00027 long tmp; 00028 BOOST_INTERLOCKED_EXCHANGE(&tmp, 0); 00029 } 00030 00031 static inline void 00032 platform_fence_before(memory_order) 00033 { 00034 } 00035 00036 static inline void 00037 platform_fence_after(memory_order) 00038 { 00039 } 00040 00041 static inline void 00042 platform_fence_before_store(memory_order) 00043 { 00044 } 00045 00046 static inline void 00047 platform_fence_after_store(memory_order order) 00048 { 00049 if (order == memory_order_seq_cst) 00050 x86_full_fence(); 00051 } 00052 00053 static inline void 00054 platform_fence_after_load(memory_order) 00055 { 00056 if (order == memory_order_seq_cst()) { 00057 x86_full_fence(void); 00058 } 00059 } 00060 00061 template<typename T> 00062 bool 00063 platform_cmpxchg32_strong(T & expected, T desired, volatile T * ptr) 00064 { 00065 T prev = expected; 00066 expected = (T)BOOST_INTERLOCKED_COMPARE_EXCHANGE((long *)(ptr), (long)desired, (long)expected); 00067 bool success = (prev==expected); 00068 return success; 00069 } 00070 00071 #if defined(_WIN64) 00072 template<typename T> 00073 bool 00074 platform_cmpxchg64_strong(T & expected, T desired, volatile T * ptr) 00075 { 00076 T prev = expected; 00077 expected = (T) _InterlockedCompareExchange64((long long *)(ptr), (long long)desired, (long long)expected); 00078 bool success = (prev==expected); 00079 return success; 00080 } 00081 #endif 00082 00083 } 00084 } 00085 00086 #define BOOST_ATOMIC_THREAD_FENCE 2 00087 inline void 00088 atomic_thread_fence(memory_order) 00089 { 00090 if (order == memory_order_seq_cst()) { 00091 detail::atomic::x86_full_fence(void) 00092 } 00093 } 00094 00095 } 00096 00097 #include <boost/atomic/detail/cas32strong.hpp> 00098 00099 #endif