comparison scripts/hvresources/HvUtils.h @ 504:b6eb94378ca9 prerelease

update_board
author Giulio Moro <giuliomoro@yahoo.it>
date Wed, 22 Jun 2016 01:24:55 +0100
parents 9e5156589124
children
comparison
equal deleted inserted replaced
503:04212032c779 504:b6eb94378ca9
40 40
41 // type definitions 41 // type definitions
42 #include <stdint.h> 42 #include <stdint.h>
43 #include <stdbool.h> 43 #include <stdbool.h>
44 #define hv_size_t size_t 44 #define hv_size_t size_t
45 #define hv_uint64_t uint64_t
45 #define hv_uint32_t uint32_t 46 #define hv_uint32_t uint32_t
46 #define hv_int32_t int32_t 47 #define hv_int32_t int32_t
47 #define hv_uint16_t uint16_t 48 #define hv_uint16_t uint16_t
48 49
49 // SIMD-specific includes 50 // SIMD-specific includes
170 #elif HV_SIMD_NEON 171 #elif HV_SIMD_NEON
171 #if HV_ANDROID 172 #if HV_ANDROID
172 #define hv_malloc(_n) memalign(16, _n) 173 #define hv_malloc(_n) memalign(16, _n)
173 #define hv_free(x) free(x) 174 #define hv_free(x) free(x)
174 #else 175 #else
175 //#define hv_malloc(_n) aligned_alloc(16, _n) 176 #define hv_malloc(_n) aligned_alloc(16, _n)
176 #define hv_malloc(_n) memalign(16, _n)
177 #define hv_free(x) free(x) 177 #define hv_free(x) free(x)
178 #endif 178 #endif
179 #else // HV_SIMD_NONE 179 #else // HV_SIMD_NONE
180 #define hv_malloc(_n) malloc(_n) 180 #define hv_malloc(_n) malloc(_n)
181 #define hv_free(_n) free(_n) 181 #define hv_free(_n) free(_n)
259 #include <Windows.h> 259 #include <Windows.h>
260 #define hv_atomic_bool volatile LONG 260 #define hv_atomic_bool volatile LONG
261 #define HV_SPINLOCK_ACQUIRE(_x) \ 261 #define HV_SPINLOCK_ACQUIRE(_x) \
262 while (InterlockedCompareExchange(&_x, true, false)) { } 262 while (InterlockedCompareExchange(&_x, true, false)) { }
263 #define HV_SPINLOCK_RELEASE(_x) (_x = false) 263 #define HV_SPINLOCK_RELEASE(_x) (_x = false)
264 #elif defined(__has_include) 264 #elif __cplusplus || __has_include(<stdatomic.h>)
265 #if __has_include(<stdatomic.h>) 265 #if !__cplusplus
266 #include <stdatomic.h> 266 #include <stdatomic.h>
267 #endif
267 #define hv_atomic_bool volatile atomic_bool 268 #define hv_atomic_bool volatile atomic_bool
268 #define HV_SPINLOCK_ACQUIRE(_x) \ 269 #define HV_SPINLOCK_ACQUIRE(_x) \
269 bool expected = false; \ 270 bool expected = false; \
270 while (!atomic_compare_exchange_strong(&_x, &expected, true)) { expected = false; } 271 while (!atomic_compare_exchange_strong(&_x, &expected, true)) { expected = false; }
271 #define HV_SPINLOCK_RELEASE(_x) atomic_store(&_x, false) 272 #define HV_SPINLOCK_RELEASE(_x) atomic_store(&_x, false)
272 #else 273 #else
273 #define hv_atomic_bool volatile bool 274 #define hv_atomic_bool volatile bool
274 #define HV_SPINLOCK_ACQUIRE(_x) _x = true; 275 #define HV_SPINLOCK_ACQUIRE(_x) _x = true;
275 #define HV_SPINLOCK_RELEASE(_x) _x = false; 276 #define HV_SPINLOCK_RELEASE(_x) _x = false;
276 #endif 277 #endif
277 #else
278 #define hv_atomic_bool volatile bool
279 #define HV_SPINLOCK_ACQUIRE(_x) _x = true;
280 #define HV_SPINLOCK_RELEASE(_x) _x = false;
281 #endif
282
283 278
284 #endif // _HEAVY_UTILS_H_ 279 #endif // _HEAVY_UTILS_H_