]> AND Private Git Repository - canny.git/blob - stc/exp/ml_stc_linux_make_v1.0/include/boost/smart_ptr/detail/atomic_count.hpp
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
f8561371fa23b6c1e03d5da45914b7ccf0c8575e
[canny.git] / stc / exp / ml_stc_linux_make_v1.0 / include / boost / smart_ptr / detail / atomic_count.hpp
1 #ifndef BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_HPP_INCLUDED\r
2 #define BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_HPP_INCLUDED\r
3 \r
4 // MS compatible compilers support #pragma once\r
5 \r
6 #if defined(_MSC_VER) && (_MSC_VER >= 1020)\r
7 # pragma once\r
8 #endif\r
9 \r
10 //\r
11 //  boost/detail/atomic_count.hpp - thread/SMP safe reference counter\r
12 //\r
13 //  Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd.\r
14 //\r
15 // Distributed under the Boost Software License, Version 1.0. (See\r
16 // accompanying file LICENSE_1_0.txt or copy at\r
17 // http://www.boost.org/LICENSE_1_0.txt)\r
18 //\r
19 //  typedef <implementation-defined> boost::detail::atomic_count;\r
20 //\r
21 //  atomic_count a(n);\r
22 //\r
23 //    (n is convertible to long)\r
24 //\r
25 //    Effects: Constructs an atomic_count with an initial value of n\r
26 //\r
27 //  a;\r
28 //\r
29 //    Returns: (long) the current value of a\r
30 //\r
31 //  ++a;\r
32 //\r
33 //    Effects: Atomically increments the value of a\r
34 //    Returns: (long) the new value of a\r
35 //\r
36 //  --a;\r
37 //\r
38 //    Effects: Atomically decrements the value of a\r
39 //    Returns: (long) the new value of a\r
40 //\r
41 //    Important note: when --a returns zero, it must act as a\r
42 //      read memory barrier (RMB); i.e. the calling thread must\r
43 //      have a synchronized view of the memory\r
44 //\r
45 //    On Intel IA-32 (x86) memory is always synchronized, so this\r
46 //      is not a problem.\r
47 //\r
48 //    On many architectures the atomic instructions already act as\r
49 //      a memory barrier.\r
50 //\r
51 //    This property is necessary for proper reference counting, since\r
52 //      a thread can update the contents of a shared object, then\r
53 //      release its reference, and another thread may immediately\r
54 //      release the last reference causing object destruction.\r
55 //\r
56 //    The destructor needs to have a synchronized view of the\r
57 //      object to perform proper cleanup.\r
58 //\r
59 //    Original example by Alexander Terekhov:\r
60 //\r
61 //    Given:\r
62 //\r
63 //    - a mutable shared object OBJ;\r
64 //    - two threads THREAD1 and THREAD2 each holding \r
65 //      a private smart_ptr object pointing to that OBJ.\r
66 //\r
67 //    t1: THREAD1 updates OBJ (thread-safe via some synchronization)\r
68 //      and a few cycles later (after "unlock") destroys smart_ptr;\r
69 //\r
70 //    t2: THREAD2 destroys smart_ptr WITHOUT doing any synchronization \r
71 //      with respect to shared mutable object OBJ; OBJ destructors\r
72 //      are called driven by smart_ptr interface...\r
73 //\r
74 \r
75 #include <boost/config.hpp>\r
76 #include <boost/smart_ptr/detail/sp_has_sync.hpp>\r
77 \r
78 #ifndef BOOST_HAS_THREADS\r
79 \r
80 namespace boost\r
81 {\r
82 \r
83 namespace detail\r
84 {\r
85 \r
86 typedef long atomic_count;\r
87 \r
88 }\r
89 \r
90 }\r
91 \r
92 #elif defined(BOOST_AC_USE_PTHREADS)\r
93 #  include <boost/smart_ptr/detail/atomic_count_pthreads.hpp>\r
94 \r
95 #elif defined( __GNUC__ ) && ( defined( __i386__ ) || defined( __x86_64__ ) )\r
96 #  include <boost/smart_ptr/detail/atomic_count_gcc_x86.hpp>\r
97 \r
98 #elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)\r
99 #  include <boost/smart_ptr/detail/atomic_count_win32.hpp>\r
100 \r
101 #elif defined( BOOST_SP_HAS_SYNC )\r
102 #  include <boost/smart_ptr/detail/atomic_count_sync.hpp>\r
103 \r
104 #elif defined(__GLIBCPP__) || defined(__GLIBCXX__)\r
105 #  include <boost/smart_ptr/detail/atomic_count_gcc.hpp>\r
106 \r
107 #elif defined(BOOST_HAS_PTHREADS)\r
108 \r
109 #  define BOOST_AC_USE_PTHREADS\r
110 #  include <boost/smart_ptr/detail/atomic_count_pthreads.hpp>\r
111 \r
112 #else\r
113 \r
114 // Use #define BOOST_DISABLE_THREADS to avoid the error\r
115 #error Unrecognized threading platform\r
116 \r
117 #endif\r
118 \r
119 #endif // #ifndef BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_HPP_INCLUDED\r