1 #ifndef BOOST_DETAIL_ATOMIC_COUNT_HPP_INCLUDED
2 #define BOOST_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 // Permission to copy, use, modify, sell and distribute this software
16 // is granted provided this copyright notice appears in all copies.
17 // This software is provided "as is" without express or implied
18 // warranty, and with no claim as to its suitability for any purpose.
20 // typedef <implementation-defined> boost::detail::atomic_count;
24 // (n is convertible to long)
26 // Effects: Constructs an atomic_count with an initial value of n
30 // Returns: (long) the current value of a
34 // Effects: Atomically increments the value of a
39 // Effects: Atomically decrements the value of a
40 // Returns: (long) zero if the new value of a is zero,
41 // unspecified non-zero value otherwise (usually the new value)
43 // Important note: when --a returns zero, it must act as a
44 // read memory barrier (RMB); i.e. the calling thread must
45 // have a synchronized view of the memory
47 // On Intel IA-32 (x86) memory is always synchronized, so this
50 // On many architectures the atomic instructions already act as
53 // This property is necessary for proper reference counting, since
54 // a thread can update the contents of a shared object, then
55 // release its reference, and another thread may immediately
56 // release the last reference causing object destruction.
58 // The destructor needs to have a synchronized view of the
59 // object to perform proper cleanup.
61 // Original example by Alexander Terekhov:
65 // - a mutable shared object OBJ;
66 // - two threads THREAD1 and THREAD2 each holding
67 // a private smart_ptr object pointing to that OBJ.
69 // t1: THREAD1 updates OBJ (thread-safe via some synchronization)
70 // and a few cycles later (after "unlock") destroys smart_ptr;
72 // t2: THREAD2 destroys smart_ptr WITHOUT doing any synchronization
73 // with respect to shared mutable object OBJ; OBJ destructors
74 // are called driven by smart_ptr interface...
77 // Note: atomic_count_linux.hpp has been disabled by default; see the
78 // comments inside for more info.
80 #include <boost/config.hpp>
82 #ifndef BOOST_HAS_THREADS
90 typedef long atomic_count;
96 #elif defined(BOOST_USE_ASM_ATOMIC_H)
97 # include <boost/detail/atomic_count_linux.hpp>
98 #elif defined(BOOST_AC_USE_PTHREADS)
99 # include <boost/detail/atomic_count_pthreads.hpp>
100 #elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
101 # include <boost/detail/atomic_count_win32.hpp>
102 #elif defined(__GLIBCPP__)
103 # include <boost/detail/atomic_count_gcc.hpp>
104 #elif defined(BOOST_HAS_PTHREADS)
105 # define BOOST_AC_USE_PTHREADS
106 # include <boost/detail/atomic_count_pthreads.hpp>
109 // Use #define BOOST_DISABLE_THREADS to avoid the error
110 #error Unrecognized threading platform
114 #endif // #ifndef BOOST_DETAIL_ATOMIC_COUNT_HPP_INCLUDED