00001 #ifndef BOOST_DETAIL_ATOMIC_COUNT_HPP_INCLUDED 00002 #define BOOST_DETAIL_ATOMIC_COUNT_HPP_INCLUDED 00003 00004 // MS compatible compilers support #pragma once 00005 00006 #if defined(_MSC_VER) && (_MSC_VER >= 1020) 00007 # pragma once 00008 #endif 00009 00010 // 00011 // boost/detail/atomic_count.hpp - thread/SMP safe reference counter 00012 // 00013 // Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd. 00014 // 00015 // Distributed under the Boost Software License, Version 1.0. (See 00016 // accompanying file LICENSE_1_0.txt or copy at 00017 // http://www.boost.org/LICENSE_1_0.txt) 00018 // 00019 // typedef <implementation-defined> boost::detail::atomic_count; 00020 // 00021 // atomic_count a(n); 00022 // 00023 // (n is convertible to long) 00024 // 00025 // Effects: Constructs an atomic_count with an initial value of n 00026 // 00027 // a; 00028 // 00029 // Returns: (long) the current value of a 00030 // 00031 // ++a; 00032 // 00033 // Effects: Atomically increments the value of a 00034 // Returns: nothing 00035 // 00036 // --a; 00037 // 00038 // Effects: Atomically decrements the value of a 00039 // Returns: (long) zero if the new value of a is zero, 00040 // unspecified non-zero value otherwise (usually the new value) 00041 // 00042 // Important note: when --a returns zero, it must act as a 00043 // read memory barrier (RMB); i.e. the calling thread must 00044 // have a synchronized view of the memory 00045 // 00046 // On Intel IA-32 (x86) memory is always synchronized, so this 00047 // is not a problem. 00048 // 00049 // On many architectures the atomic instructions already act as 00050 // a memory barrier. 00051 // 00052 // This property is necessary for proper reference counting, since 00053 // a thread can update the contents of a shared object, then 00054 // release its reference, and another thread may immediately 00055 // release the last reference causing object destruction. 00056 // 00057 // The destructor needs to have a synchronized view of the 00058 // object to perform proper cleanup. 00059 // 00060 // Original example by Alexander Terekhov: 00061 // 00062 // Given: 00063 // 00064 // - a mutable shared object OBJ; 00065 // - two threads THREAD1 and THREAD2 each holding 00066 // a private smart_ptr object pointing to that OBJ. 00067 // 00068 // t1: THREAD1 updates OBJ (thread-safe via some synchronization) 00069 // and a few cycles later (after "unlock") destroys smart_ptr; 00070 // 00071 // t2: THREAD2 destroys smart_ptr WITHOUT doing any synchronization 00072 // with respect to shared mutable object OBJ; OBJ destructors 00073 // are called driven by smart_ptr interface... 00074 // 00075 00076 #include <sysc/packages/boost/config.hpp> 00077 00078 #ifndef BOOST_HAS_THREADS 00079 00080 namespace boost 00081 { 00082 00083 namespace detail 00084 { 00085 00086 typedef long atomic_count; 00087 00088 } 00089 00090 } 00091 00092 #elif defined(BOOST_AC_USE_PTHREADS) 00093 # include <sysc/packages/boost/detail/atomic_count_pthreads.hpp> 00094 #elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) 00095 # include <sysc/packages/boost/detail/atomic_count_win32.hpp> 00096 #elif defined(__GLIBCPP__) || defined(__GLIBCXX__) 00097 # include <sysc/packages/boost/detail/atomic_count_gcc.hpp> 00098 #elif defined(BOOST_HAS_PTHREADS) 00099 # define BOOST_AC_USE_PTHREADS 00100 # include <sysc/packages/boost/detail/atomic_count_pthreads.hpp> 00101 #else 00102 00103 // Use #define BOOST_DISABLE_THREADS to avoid the error 00104 #error Unrecognized threading platform 00105 00106 #endif 00107 00108 #endif // #ifndef BOOST_DETAIL_ATOMIC_COUNT_HPP_INCLUDED
1.5.5