1 /* 2 * Copyright 2008, Axel Dörfler, axeld@pinc-software.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _KERNEL_UTIL_ATOMIC_H 6 #define _KERNEL_UTIL_ATOMIC_H 7 8 9 #include <limits.h> 10 11 #include <SupportDefs.h> 12 13 14 #ifdef __cplusplus 15 16 template<typename PointerType> PointerType* 17 atomic_pointer_test_and_set(PointerType** _pointer, const PointerType* set, 18 const PointerType* test) 19 { 20 #if LONG_MAX == INT_MAX 21 return (PointerType*)atomic_test_and_set((vint32*)_pointer, (int32)set, 22 (int32)test); 23 #else 24 return (PointerType*)atomic_test_and_set64((vint64*)_pointer, (int64)set, 25 (int64)test); 26 #endif 27 } 28 29 30 template<typename PointerType> PointerType* 31 atomic_pointer_set(PointerType** _pointer, const PointerType* set) 32 { 33 #if LONG_MAX == INT_MAX 34 return (PointerType*)atomic_set((vint32*)_pointer, (int32)set); 35 #else 36 return (PointerType*)atomic_set64((vint64*)_pointer, (int64)set); 37 #endif 38 } 39 40 41 template<typename PointerType> PointerType* 42 atomic_pointer_get(PointerType** _pointer) 43 { 44 #if LONG_MAX == INT_MAX 45 return (PointerType*)atomic_get((vint32*)_pointer); 46 #else 47 return (PointerType*)atomic_get64((vint64*)_pointer); 48 #endif 49 } 50 51 #endif // __cplusplus 52 53 #endif /* _KERNEL_UTIL_ATOMIC_H */ 54