| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
#ifndef ECL_ATOMICS_H |
| 14 |
#define ECL_ATOMICS_H |
| 15 |
|
| 16 |
#ifdef ECL_THREADS |
| 17 |
|
| 18 |
# define AO_REQUIRE_CAS |
| 19 |
# define AO_ASSUME_WINDOWS98 |
| 20 |
# ifdef ECL_LIBATOMIC_OPS_H |
| 21 |
# include <ecl/atomic_ops.h> |
| 22 |
# else |
| 23 |
# include <atomic_ops.h> |
| 24 |
# endif |
| 25 |
|
| 26 |
# if !defined(AO_HAVE_compare_and_swap_full) |
| 27 |
# error "ECL needs AO_compare_and_swap_full or an equivalent" |
| 28 |
# endif |
| 29 |
# if !defined(AO_HAVE_compare_and_swap) |
| 30 |
# error "ECL needs AO_compare_and_swap or an equivalent" |
| 31 |
# endif |
| 32 |
# if !defined(AO_HAVE_fetch_and_add) |
| 33 |
# error "ECL needs AO_fetch_and_add or an equivalent" |
| 34 |
# endif |
| 35 |
# if !defined(AO_HAVE_fetch_compare_and_swap) |
| 36 |
# error "ECL needs AO_fetch_compare_and_swap or an equivalent" |
| 37 |
# endif |
| 38 |
|
| 39 |
static inline cl_object |
| 40 |
ecl_compare_and_swap(cl_object *slot, cl_object old_val, cl_object new_val) |
| 41 |
{ |
| 42 |
return (cl_object)AO_fetch_compare_and_swap((AO_t*)slot, (AO_t)old_val, (AO_t)new_val); |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
static inline cl_object |
| 49 |
ecl_atomic_incf(cl_object *slot, cl_object increment) |
| 50 |
{ |
| 51 |
if (ecl_unlikely(!ECL_FIXNUMP(increment))) |
| 52 |
FEtype_error_fixnum(increment); |
| 53 |
return (cl_object)AO_fetch_and_add((AO_t*)slot, (AO_t)increment & ~(AO_t)ECL_IMMEDIATE_TAG); |
| 54 |
} |
| 55 |
|
| 56 |
static inline cl_object |
| 57 |
ecl_atomic_incf_by_fixnum(cl_object *slot, cl_fixnum increment) |
| 58 |
{ |
| 59 |
|
| 60 |
return (cl_object)AO_fetch_and_add((AO_t*)slot, (AO_t)increment << ECL_TAG_BITS); |
| 61 |
} |
| 62 |
|
| 63 |
#else |
| 64 |
|
| 65 |
# define AO_load(x) (x) |
| 66 |
# define AO_store(x,y) ((x)=(y)) |
| 67 |
# define AO_nop_full() |
| 68 |
|
| 69 |
#endif |
| 70 |
|
| 71 |
#endif |