Debian Codegraph @

src/h/ecl_atomics.h

raw symbols SCIP
1 /* -*- Mode: C; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /* vim: set filetype=c tabstop=2 shiftwidth=2 expandtab: */
3
4 /*
5 * ecl_atomics.h - alternative definitions for atomic operations
6 *
7 * Copyright (c) 2012 Juan Jose Garcia Ripoll
8 *
9 * See file 'LICENSE' for the copyright details.
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 /* Atomic increment of fixnums: If we don't care about overflows, we
46 can add two fixnums together by adding a normal fixnum to another
47 fixnum which has its tag bits set to zero. */
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 /* INV: AO_t is an unsigned integer, hence shifts will always zero fill */
60 return (cl_object)AO_fetch_and_add((AO_t*)slot, (AO_t)increment << ECL_TAG_BITS);
61 }
62
63 #else /* ECL_THREADS */
64
65 # define AO_load(x) (x)
66 # define AO_store(x,y) ((x)=(y))
67 # define AO_nop_full()
68
69 #endif /* ECL_THREADS */
70
71 #endif /* ECL_ATOMICS_H */