comparison DEPENDENCIES/generic/include/boost/interprocess/detail/atomic.hpp @ 101:c530137014c0

Update Boost headers (1.58.0)
author Chris Cannam
date Mon, 07 Sep 2015 11:12:49 +0100
parents 2665513ce2d3
children
comparison
equal deleted inserted replaced
100:793467b5e61c 101:c530137014c0
13 ////////////////////////////////////////////////////////////////////////////// 13 //////////////////////////////////////////////////////////////////////////////
14 14
15 #ifndef BOOST_INTERPROCESS_DETAIL_ATOMIC_HPP 15 #ifndef BOOST_INTERPROCESS_DETAIL_ATOMIC_HPP
16 #define BOOST_INTERPROCESS_DETAIL_ATOMIC_HPP 16 #define BOOST_INTERPROCESS_DETAIL_ATOMIC_HPP
17 17
18 #ifndef BOOST_CONFIG_HPP
19 # include <boost/config.hpp>
20 #endif
21 #
22 #if defined(BOOST_HAS_PRAGMA_ONCE)
23 # pragma once
24 #endif
25
18 #include <boost/interprocess/detail/config_begin.hpp> 26 #include <boost/interprocess/detail/config_begin.hpp>
19 #include <boost/interprocess/detail/workaround.hpp> 27 #include <boost/interprocess/detail/workaround.hpp>
20 #include <boost/cstdint.hpp> 28 #include <boost/cstdint.hpp>
21 29
22 namespace boost{ 30 namespace boost{
47 55
48 } //namespace ipcdetail{ 56 } //namespace ipcdetail{
49 } //namespace interprocess{ 57 } //namespace interprocess{
50 } //namespace boost{ 58 } //namespace boost{
51 59
52 #if (defined BOOST_INTERPROCESS_WINDOWS) 60 #if defined (BOOST_INTERPROCESS_WINDOWS)
53 61
54 #include <boost/interprocess/detail/win32_api.hpp> 62 #include <boost/interprocess/detail/win32_api.hpp>
63
64 #if defined( _MSC_VER )
65 extern "C" void _ReadWriteBarrier(void);
66 #pragma intrinsic(_ReadWriteBarrier)
67 #define BOOST_INTERPROCESS_READ_WRITE_BARRIER _ReadWriteBarrier()
68 #elif defined(__GNUC__)
69 #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) > 40100
70 #define BOOST_INTERPROCESS_READ_WRITE_BARRIER __sync_synchronize()
71 #else
72 #define BOOST_INTERPROCESS_READ_WRITE_BARRIER __asm__ __volatile__("" : : : "memory")
73 #endif
74 #endif
55 75
56 namespace boost{ 76 namespace boost{
57 namespace interprocess{ 77 namespace interprocess{
58 namespace ipcdetail{ 78 namespace ipcdetail{
59 79
69 inline boost::uint32_t atomic_inc32(volatile boost::uint32_t *mem) 89 inline boost::uint32_t atomic_inc32(volatile boost::uint32_t *mem)
70 { return winapi::interlocked_increment(reinterpret_cast<volatile long*>(mem))-1; } 90 { return winapi::interlocked_increment(reinterpret_cast<volatile long*>(mem))-1; }
71 91
72 //! Atomically read an boost::uint32_t from memory 92 //! Atomically read an boost::uint32_t from memory
73 inline boost::uint32_t atomic_read32(volatile boost::uint32_t *mem) 93 inline boost::uint32_t atomic_read32(volatile boost::uint32_t *mem)
74 { return *mem; } 94 {
95 const boost::uint32_t val = *mem;
96 BOOST_INTERPROCESS_READ_WRITE_BARRIER;
97 return val;
98 }
75 99
76 //! Atomically set an boost::uint32_t in memory 100 //! Atomically set an boost::uint32_t in memory
77 //! "mem": pointer to the object 101 //! "mem": pointer to the object
78 //! "param": val value that the object will assume 102 //! "param": val value that the object will assume
79 inline void atomic_write32(volatile boost::uint32_t *mem, boost::uint32_t val) 103 inline void atomic_write32(volatile boost::uint32_t *mem, boost::uint32_t val)
91 115
92 } //namespace ipcdetail{ 116 } //namespace ipcdetail{
93 } //namespace interprocess{ 117 } //namespace interprocess{
94 } //namespace boost{ 118 } //namespace boost{
95 119
96 #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) 120 #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) && !defined(_CRAYC)
97 121
98 namespace boost { 122 namespace boost {
99 namespace interprocess { 123 namespace interprocess {
100 namespace ipcdetail{ 124 namespace ipcdetail{
101 125
155 inline boost::uint32_t atomic_dec32(volatile boost::uint32_t *mem) 179 inline boost::uint32_t atomic_dec32(volatile boost::uint32_t *mem)
156 { return atomic_add32(mem, (boost::uint32_t)-1); } 180 { return atomic_add32(mem, (boost::uint32_t)-1); }
157 181
158 //! Atomically read an boost::uint32_t from memory 182 //! Atomically read an boost::uint32_t from memory
159 inline boost::uint32_t atomic_read32(volatile boost::uint32_t *mem) 183 inline boost::uint32_t atomic_read32(volatile boost::uint32_t *mem)
160 { return *mem; } 184 {
185 const boost::uint32_t val = *mem;
186 __asm__ __volatile__ ( "" ::: "memory" );
187 return val;
188 }
161 189
162 //! Atomically set an boost::uint32_t in memory 190 //! Atomically set an boost::uint32_t in memory
163 //! "mem": pointer to the object 191 //! "mem": pointer to the object
164 //! "param": val value that the object will assume 192 //! "param": val value that the object will assume
165 inline void atomic_write32(volatile boost::uint32_t *mem, boost::uint32_t val) 193 inline void atomic_write32(volatile boost::uint32_t *mem, boost::uint32_t val)
166 { *mem = val; } 194 {
195 __asm__ __volatile__
196 (
197 "xchgl %0, %1"
198 : "+r" (val), "+m" (*mem)
199 :: "memory"
200 );
201 }
167 202
168 } //namespace ipcdetail{ 203 } //namespace ipcdetail{
169 } //namespace interprocess{ 204 } //namespace interprocess{
170 } //namespace boost{ 205 } //namespace boost{
171 206
230 inline boost::uint32_t atomic_dec32(volatile boost::uint32_t *mem) 265 inline boost::uint32_t atomic_dec32(volatile boost::uint32_t *mem)
231 { return atomic_add32(mem, boost::uint32_t(-1u)); } 266 { return atomic_add32(mem, boost::uint32_t(-1u)); }
232 267
233 //! Atomically read an boost::uint32_t from memory 268 //! Atomically read an boost::uint32_t from memory
234 inline boost::uint32_t atomic_read32(volatile boost::uint32_t *mem) 269 inline boost::uint32_t atomic_read32(volatile boost::uint32_t *mem)
235 { return *mem; } 270 {
271 const boost::uint32_t val = *mem;
272 __asm__ __volatile__ ( "" ::: "memory" );
273 return val;
274 }
236 275
237 //! Atomically set an boost::uint32_t in memory 276 //! Atomically set an boost::uint32_t in memory
238 //! "mem": pointer to the object 277 //! "mem": pointer to the object
239 //! "param": val value that the object will assume 278 //! "param": val value that the object will assume
240 inline void atomic_write32(volatile boost::uint32_t *mem, boost::uint32_t val) 279 inline void atomic_write32(volatile boost::uint32_t *mem, boost::uint32_t val)
508 inline boost::uint32_t atomic_dec32(volatile boost::uint32_t *mem) 547 inline boost::uint32_t atomic_dec32(volatile boost::uint32_t *mem)
509 { return atomic_add32(mem, (boost::uint32_t)-1); } 548 { return atomic_add32(mem, (boost::uint32_t)-1); }
510 549
511 //! Atomically read an boost::uint32_t from memory 550 //! Atomically read an boost::uint32_t from memory
512 inline boost::uint32_t atomic_read32(volatile boost::uint32_t *mem) 551 inline boost::uint32_t atomic_read32(volatile boost::uint32_t *mem)
513 { return *mem; } 552 { boost::uint32_t old_val = *mem; __sync_synchronize(); return old_val; }
514 553
515 //! Compare an boost::uint32_t's value with "cmp". 554 //! Compare an boost::uint32_t's value with "cmp".
516 //! If they are the same swap the value with "with" 555 //! If they are the same swap the value with "with"
517 //! "mem": pointer to the value 556 //! "mem": pointer to the value
518 //! "with" what to swap it with 557 //! "with" what to swap it with
524 563
525 //! Atomically set an boost::uint32_t in memory 564 //! Atomically set an boost::uint32_t in memory
526 //! "mem": pointer to the object 565 //! "mem": pointer to the object
527 //! "param": val value that the object will assume 566 //! "param": val value that the object will assume
528 inline void atomic_write32(volatile boost::uint32_t *mem, boost::uint32_t val) 567 inline void atomic_write32(volatile boost::uint32_t *mem, boost::uint32_t val)
529 { *mem = val; } 568 { __sync_synchronize(); *mem = val; }
530 569
531 } //namespace ipcdetail{ 570 } //namespace ipcdetail{
532 } //namespace interprocess{ 571 } //namespace interprocess{
533 } //namespace boost{ 572 } //namespace boost{
534 573