48 #if defined(VTK_HAVE_SYNC_BUILTINS) 49 # define VTK_GCC_ATOMICS_32 50 # if VTK_SIZEOF_VOID_P == 8 51 # define VTK_GCC_ATOMICS_64 53 #elif defined(__APPLE__) 54 # include <libkern/OSAtomic.h> 55 # define VTK_APPLE_ATOMICS_32 56 # if VTK_SIZEOF_VOID_P == 8 57 # define VTK_APPLE_ATOMICS_64 59 #elif defined(_WIN32) && defined(_MSC_VER) 60 # define VTK_WINDOWS_ATOMICS_32 61 # if VTK_SIZEOF_VOID_P == 8 62 # define VTK_WINDOWS_ATOMICS_64 67 #if defined(_WIN32) && defined(_MSC_VER) 69 # pragma warning(disable:4324) 70 # define VTK_ALIGN(X) __declspec(align(X)) 71 #elif defined(__GNUC__) // gcc compatible compiler 72 # define VTK_ALIGN(X) __attribute__ ((aligned (X))) 87 #if defined(VTK_GCC_ATOMICS_64) 91 typedef vtkTypeInt64
VTK_ALIGN(8) atomic_type;
92 typedef vtkTypeInt64 value_type;
94 static value_type AddAndFetch(value_type *ref, value_type val)
96 return __sync_add_and_fetch(ref, val);
99 static value_type SubAndFetch(value_type *ref, value_type val)
101 return __sync_sub_and_fetch(ref, val);
104 static value_type PreIncrement(value_type *ref)
106 return __sync_add_and_fetch(ref, 1);
109 static value_type PreDecrement(value_type *ref)
111 return __sync_sub_and_fetch(ref, 1);
114 static value_type PostIncrement(value_type *ref)
116 return __sync_fetch_and_add(ref, 1);
119 static value_type PostDecrement(value_type *ref)
121 return __sync_fetch_and_sub(ref, 1);
124 static value_type Load(
const value_type *ref)
126 __sync_synchronize();
127 return *static_cast<const volatile value_type *>(ref);
130 static void Store(value_type *ref, value_type val)
132 *static_cast<volatile value_type*>(ref) = val;
133 __sync_synchronize();
137 #elif defined(VTK_APPLE_ATOMICS_64) 138 template <>
class AtomicOps<8>
141 typedef vtkTypeInt64
VTK_ALIGN(8) atomic_type;
142 typedef vtkTypeInt64 value_type;
144 static vtkTypeInt64 AddAndFetch(vtkTypeInt64 *ref, vtkTypeInt64 val)
146 return OSAtomicAdd64Barrier(val, ref);
149 static vtkTypeInt64 SubAndFetch(vtkTypeInt64 *ref, vtkTypeInt64 val)
151 return OSAtomicAdd64Barrier(-val, ref);
154 static vtkTypeInt64 PreIncrement(vtkTypeInt64 *ref)
156 return OSAtomicIncrement64Barrier(ref);
159 static vtkTypeInt64 PreDecrement(vtkTypeInt64 *ref)
161 return OSAtomicDecrement64Barrier(ref);
164 static vtkTypeInt64 PostIncrement(vtkTypeInt64 *ref)
166 vtkTypeInt64 val = OSAtomicIncrement64Barrier(ref);
170 static vtkTypeInt64 PostDecrement(vtkTypeInt64 *ref)
172 vtkTypeInt64 val = OSAtomicDecrement64Barrier(ref);
176 static vtkTypeInt64 Load(
const vtkTypeInt64 *ref);
179 return *static_cast<const volatile vtkTypeInt64*>(ref);
182 static void Store(vtkTypeInt64 *ref, vtkTypeInt64 val);
184 *static_cast<volatile vtkTypeInt64*>(ref) = val;
194 #if defined(VTK_WINDOWS_ATOMICS_64) 195 typedef vtkTypeInt64
VTK_ALIGN(8) atomic_type;
202 atomic_type(vtkTypeInt64 init);
208 static vtkTypeInt64 AddAndFetch(atomic_type *ref, vtkTypeInt64 val);
209 static vtkTypeInt64 SubAndFetch(atomic_type *ref, vtkTypeInt64 val);
210 static vtkTypeInt64 PreIncrement(atomic_type *ref);
211 static vtkTypeInt64 PreDecrement(atomic_type *ref);
212 static vtkTypeInt64 PostIncrement(atomic_type *ref);
213 static vtkTypeInt64 PostDecrement(atomic_type *ref);
214 static vtkTypeInt64 Load(
const atomic_type *ref);
215 static void Store(atomic_type *ref, vtkTypeInt64 val);
220 #if defined(VTK_GCC_ATOMICS_32) 229 return __sync_add_and_fetch(ref, val);
234 return __sync_sub_and_fetch(ref, val);
239 return __sync_add_and_fetch(ref, 1);
244 return __sync_sub_and_fetch(ref, 1);
249 return __sync_fetch_and_add(ref, 1);
254 return __sync_fetch_and_sub(ref, 1);
259 __sync_synchronize();
260 return *static_cast<const volatile value_type *>(ref);
265 *static_cast<volatile value_type*>(ref) = val;
266 __sync_synchronize();
270 #elif defined(VTK_APPLE_ATOMICS_32) 271 template <>
class AtomicOps<4>
274 typedef vtkTypeInt32
VTK_ALIGN(4) atomic_type;
275 typedef vtkTypeInt32 value_type;
277 static vtkTypeInt32 AddAndFetch(vtkTypeInt32 *ref, vtkTypeInt32 val)
279 return OSAtomicAdd32Barrier(val, ref);
282 static vtkTypeInt32 SubAndFetch(vtkTypeInt32 *ref, vtkTypeInt32 val)
284 return OSAtomicAdd32Barrier(-val, ref);
287 static vtkTypeInt32 PreIncrement(vtkTypeInt32 *ref)
289 return OSAtomicIncrement32Barrier(ref);
292 static vtkTypeInt32 PreDecrement(vtkTypeInt32 *ref)
294 return OSAtomicDecrement32Barrier(ref);
297 static vtkTypeInt32 PostIncrement(vtkTypeInt32 *ref)
299 vtkTypeInt32 val = OSAtomicIncrement32Barrier(ref);
303 static vtkTypeInt32 PostDecrement(vtkTypeInt32 *ref)
305 vtkTypeInt32 val = OSAtomicDecrement32Barrier(ref);
309 static vtkTypeInt32 Load(
const vtkTypeInt32 *ref);
312 return *static_cast<const volatile vtkTypeInt32*>(ref);
315 static void Store(vtkTypeInt32 *ref, vtkTypeInt32 val);
317 *static_cast<volatile vtkTypeInt32*>(ref) = val;
327 #if defined(VTK_WINDOWS_ATOMICS_32) 328 typedef vtkTypeInt32
VTK_ALIGN(4) atomic_type;
335 atomic_type(vtkTypeInt32 init);
339 typedef vtkTypeInt32 value_type;
341 static vtkTypeInt32 AddAndFetch(atomic_type *ref, vtkTypeInt32 val);
342 static vtkTypeInt32 SubAndFetch(atomic_type *ref, vtkTypeInt32 val);
343 static vtkTypeInt32 PreIncrement(atomic_type *ref);
344 static vtkTypeInt32 PreDecrement(atomic_type *ref);
345 static vtkTypeInt32 PostIncrement(atomic_type *ref);
346 static vtkTypeInt32 PostDecrement(atomic_type *ref);
347 static vtkTypeInt32 Load(
const atomic_type *ref);
348 static void Store(atomic_type *ref, vtkTypeInt32 val);
353 #endif // __VTK_WRAP__ 370 : Atomic(static_cast<typename
Impl::value_type>(atomic.
load()))
376 return static_cast<T>(Impl::PreIncrement(&this->Atomic));
381 return static_cast<T>(Impl::PostIncrement(&this->Atomic));
386 return static_cast<T>(Impl::PreDecrement(&this->Atomic));
391 return static_cast<T>(Impl::PostDecrement(&this->Atomic));
396 return static_cast<T>(Impl::AddAndFetch(&this->Atomic,
397 static_cast<typename Impl::value_type>(val)));
402 return static_cast<T>(Impl::SubAndFetch(&this->Atomic,
403 static_cast<typename Impl::value_type>(val)));
408 return static_cast<T>(Impl::Load(&this->Atomic));
413 Impl::Store(&this->Atomic, static_cast<typename Impl::value_type>(val));
425 return static_cast<T>(Impl::Load(&this->Atomic));
430 Impl::Store(&this->Atomic, static_cast<typename Impl::value_type>(val));
434 typename Impl::atomic_type Atomic;
449 : Atomic(reinterpret_cast<typename
Impl::value_type>(val))
454 : Atomic(reinterpret_cast<typename
Impl::value_type>(atomic.
load()))
460 return reinterpret_cast<T*>(Impl::AddAndFetch(&this->Atomic,
sizeof(T)));
465 T* val = reinterpret_cast<T*>(Impl::AddAndFetch(&this->Atomic,
sizeof(T)));
471 return reinterpret_cast<T*>(Impl::SubAndFetch(&this->Atomic,
sizeof(T)));
476 T* val = reinterpret_cast<T*>(Impl::AddAndFetch(&this->Atomic,
sizeof(T)));
482 return reinterpret_cast<T*>(Impl::AddAndFetch(&this->Atomic,
488 return reinterpret_cast<T*>(Impl::SubAndFetch(&this->Atomic,
494 return reinterpret_cast<T*>(Impl::Load(&this->Atomic));
499 Impl::Store(&this->Atomic,
500 reinterpret_cast<typename Impl::value_type>(val));
512 return reinterpret_cast<T*>(Impl::Load(&this->Atomic));
517 Impl::Store(&this->Atomic,
518 reinterpret_cast<typename Impl::value_type>(val));
522 typename Impl::atomic_type Atomic;
537 : Atomic(reinterpret_cast<
Impl::value_type>(val))
542 : Atomic(reinterpret_cast<
Impl::value_type>(atomic.
load()))
546 operator void*()
const 548 return reinterpret_cast<void*>(Impl::Load(&this->Atomic));
553 Impl::Store(&this->Atomic,
554 reinterpret_cast<Impl::value_type>(val));
566 return reinterpret_cast<void*>(Impl::Load(&this->Atomic));
571 Impl::Store(&this->Atomic,
572 reinterpret_cast<Impl::value_type>(val));
576 Impl::atomic_type Atomic;
vtkAtomic< T > & operator=(const vtkAtomic< T > &atomic)
vtkSimpleCriticalSection * csec
static value_type Load(const value_type *ref)
T * operator+=(std::ptrdiff_t val)
#define VTKCOMMONCORE_EXPORT
static value_type PostIncrement(value_type *ref)
static void Store(value_type *ref, value_type val)
vtkAtomic(const vtkAtomic< T > &atomic)
static value_type PostDecrement(value_type *ref)
static value_type PreDecrement(value_type *ref)
vtkAtomic< T * > & operator=(const vtkAtomic< T * > &atomic)
static value_type SubAndFetch(value_type *ref, value_type val)
static value_type PreIncrement(value_type *ref)
T * operator-=(std::ptrdiff_t val)
vtkTypeInt32 VTK_ALIGN(4) atomic_type
vtkAtomic< void * > & operator=(const vtkAtomic< void * > &atomic)
Critical section locking class.
vtkAtomic(const vtkAtomic< void * > &atomic)
void * operator=(void *val)
vtkAtomic(const vtkAtomic< T * > &atomic)