PFUNC
1.0
|
00001 #ifndef PFUNC_ATOMICS_HPP 00002 #define PFUNC_ATOMICS_HPP 00003 00011 #include <pfunc/config.h> 00012 #include <pfunc/environ.hpp> 00013 00014 #if defined (c_plusplus) || defined (__cplusplus) 00015 extern "C" { 00016 #endif 00017 00018 #if PFUNC_HAVE_STDINT_H == 1 00019 #include <stdint.h> 00020 #else 00021 typedef _int32 int32_t; 00022 typedef _int16 int16_t; 00023 typedef _int8 int8_t; 00024 #endif 00025 00042 static PFUNC_INLINE int8_t pfunc_compare_and_swap_8 00043 (volatile void* dest, int8_t exchg, int8_t comprnd); 00044 00061 static PFUNC_INLINE int16_t pfunc_compare_and_swap_16 00062 (volatile void* dest, int16_t exchg, int16_t comprnd); 00063 00080 static PFUNC_INLINE int32_t pfunc_compare_and_swap_32 00081 (volatile void* dest, int32_t exchg, int32_t comprnd); 00082 00095 static PFUNC_INLINE int8_t pfunc_fetch_and_store_8 00096 (volatile void* location, int8_t new_val); 00097 00110 static PFUNC_INLINE int16_t pfunc_fetch_and_store_16 00111 (volatile void* location, int16_t new_val); 00112 00125 static PFUNC_INLINE int32_t pfunc_fetch_and_store_32 00126 (volatile void* location, int32_t new_val); 00127 00140 static PFUNC_INLINE int8_t pfunc_fetch_and_add_8 00141 (volatile void* location, int8_t addend); 00142 00155 static PFUNC_INLINE int16_t pfunc_fetch_and_add_16 00156 (volatile void* location, int16_t addend); 00157 00170 static PFUNC_INLINE int32_t pfunc_fetch_and_add_32 00171 (volatile void* location, int32_t addend); 00172 00179 static PFUNC_INLINE int8_t pfunc_read_with_fence_8 (volatile void* location); 00180 00187 static PFUNC_INLINE int16_t pfunc_read_with_fence_16 (volatile void* location); 00188 00195 static PFUNC_INLINE int32_t pfunc_read_with_fence_32 (volatile void* location); 00196 00203 static PFUNC_INLINE void pfunc_write_with_fence_8 00204 (volatile void* location, int8_t value); 00205 00212 static PFUNC_INLINE void pfunc_write_with_fence_16 00213 (volatile void* location, int16_t value); 00214 00221 static PFUNC_INLINE void pfunc_write_with_fence_32 00222 (volatile void* location, int32_t value); 00223 00224 #if defined (c_plusplus) || defined (__cplusplus) 00225 } 00226 #endif 00227 00228 /******************************************************** 00229 * BEGIN: Cast operators 00230 *******************************************************/ 00231 #if defined (c_plusplus) || defined (__cplusplus) 00232 00233 #define PFUNC_STATIC_CAST(T, expr) static_cast<T>(expr) 00234 #define PFUNC_CONST_CAST(T, expr) const_cast<T>(expr) 00235 #define PFUNC_DYNAMIC_CAST(T, expr) dynamic_cast<T>(expr) 00236 #define PFUNC_REINTERPRET_CAST(T, expr) reinterpret_cast<T>(expr) 00237 00238 #else /* use the regular C-style cast */ 00239 00240 #define PFUNC_STATIC_CAST(T, expr) (T)(expr) 00241 #define PFUNC_CONST_CAST(T, expr) (T)(expr) 00242 #define PFUNC_DYNAMIC_CAST(T, expr) (T)(expr) 00243 #define PFUNC_REINTERPRET_CAST(T, expr) (T)(expr) 00244 00245 #endif 00246 /******************************************************** 00247 * END: Cast operators 00248 *******************************************************/ 00249 00251 #if PFUNC_WINDOWS == 1 00252 #include <pfunc/asm/win.h> 00253 #elif PFUNC_X86 == 1 00254 #include <pfunc/asm/x86.h> 00255 #elif PFUNC_PPC == 1 && PFUNC_HAVE_PTHREADS == 1 00256 #include <pfunc/asm/ppc.h> 00257 #include <pfunc/asm/generic.h> 00258 #elif PFUNC_HAVE_PTHREADS == 1 00259 #include <pfunc/asm/generic.h> 00260 #endif 00261 00262 #endif