1 #ifndef BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_HPP_INCLUDED
2 #define BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_HPP_INCLUDED
4 // MS compatible compilers support #pragma once
6 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
11 // boost/detail/atomic_count.hpp - thread/SMP safe reference counter
13 // Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd.
15 // Distributed under the Boost Software License, Version 1.0. (See
16 // accompanying file LICENSE_1_0.txt or copy at
17 // http://www.boost.org/LICENSE_1_0.txt)
19 // typedef <implementation-defined> boost::detail::atomic_count;
23 // (n is convertible to long)
25 // Effects: Constructs an atomic_count with an initial value of n
29 // Returns: (long) the current value of a
33 // Effects: Atomically increments the value of a
34 // Returns: (long) the new value of a
38 // Effects: Atomically decrements the value of a
39 // Returns: (long) the new value of a
41 // Important note: when --a returns zero, it must act as a
42 // read memory barrier (RMB); i.e. the calling thread must
43 // have a synchronized view of the memory
45 // On Intel IA-32 (x86) memory is always synchronized, so this
48 // On many architectures the atomic instructions already act as
51 // This property is necessary for proper reference counting, since
52 // a thread can update the contents of a shared object, then
53 // release its reference, and another thread may immediately
54 // release the last reference causing object destruction.
56 // The destructor needs to have a synchronized view of the
57 // object to perform proper cleanup.
59 // Original example by Alexander Terekhov:
63 // - a mutable shared object OBJ;
64 // - two threads THREAD1 and THREAD2 each holding
65 // a private smart_ptr object pointing to that OBJ.
67 // t1: THREAD1 updates OBJ (thread-safe via some synchronization)
68 // and a few cycles later (after "unlock") destroys smart_ptr;
70 // t2: THREAD2 destroys smart_ptr WITHOUT doing any synchronization
71 // with respect to shared mutable object OBJ; OBJ destructors
72 // are called driven by smart_ptr interface...
75 #include <boost/config.hpp>
76 #include <boost/smart_ptr/detail/sp_has_sync.hpp>
78 #ifndef BOOST_HAS_THREADS
86 typedef long atomic_count;
92 #elif defined(BOOST_AC_USE_PTHREADS)
93 # include <boost/smart_ptr/detail/atomic_count_pthreads.hpp>
95 #elif defined( __GNUC__ ) && ( defined( __i386__ ) || defined( __x86_64__ ) )
96 # include <boost/smart_ptr/detail/atomic_count_gcc_x86.hpp>
98 #elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
99 # include <boost/smart_ptr/detail/atomic_count_win32.hpp>
101 #elif defined( BOOST_SP_HAS_SYNC )
102 # include <boost/smart_ptr/detail/atomic_count_sync.hpp>
104 #elif defined(__GLIBCPP__) || defined(__GLIBCXX__)
105 # include <boost/smart_ptr/detail/atomic_count_gcc.hpp>
107 #elif defined(BOOST_HAS_PTHREADS)
109 # define BOOST_AC_USE_PTHREADS
110 # include <boost/smart_ptr/detail/atomic_count_pthreads.hpp>
114 // Use #define BOOST_DISABLE_THREADS to avoid the error
115 #error Unrecognized threading platform
119 #endif // #ifndef BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_HPP_INCLUDED