2 * macros for manipulating pseudo-atomic flags (per thread)
6 * This software is part of the SBCL system. See the README file for
9 * This software is derived from the CMU CL system, which was
10 * written at Carnegie Mellon University and released into the
11 * public domain. The software is in the public domain and is
12 * provided with absolutely no warranty. See the COPYING and CREDITS
13 * files for more information.
16 #ifndef PSEUDO_ATOMIC_H
17 #define PSEUDO_ATOMIC_H
19 #if defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64)
21 #define set_alloc_pointer(value) \
22 SetSymbolValue(ALLOCATION_POINTER, value, 0)
23 #define get_alloc_pointer() \
24 SymbolValue(ALLOCATION_POINTER, 0)
26 #if defined(LISP_FEATURE_X86)
27 #define LISPOBJ_ASM_SUFFIX "l"
28 #elif defined(LISP_FEATURE_X86_64)
29 #define LISPOBJ_ASM_SUFFIX "q"
33 get_pseudo_atomic_atomic(struct thread
*thread
)
35 return SymbolValue(PSEUDO_ATOMIC_BITS
, thread
) & (~1);
39 set_pseudo_atomic_atomic(struct thread
*thread
)
41 lispobj
*p
= SymbolValueAddress(PSEUDO_ATOMIC_BITS
, thread
);
43 lose("set_pseudo_atomic_atomic: pseudo atomic bits is %d.", *p
);
45 ("or" LISPOBJ_ASM_SUFFIX
" %0,%1"
52 clear_pseudo_atomic_atomic(struct thread
*thread
)
54 lispobj
*p
= SymbolValueAddress(PSEUDO_ATOMIC_BITS
, thread
);
56 ("and" LISPOBJ_ASM_SUFFIX
" %0,%1"
63 get_pseudo_atomic_interrupted(struct thread
*thread
)
65 return SymbolValue(PSEUDO_ATOMIC_BITS
, thread
) & 1;
69 set_pseudo_atomic_interrupted(struct thread
*thread
)
71 if (!get_pseudo_atomic_atomic(thread
))
72 lose("set_pseudo_atomic_interrupted not in pseudo atomic");
73 lispobj
*p
= SymbolValueAddress(PSEUDO_ATOMIC_BITS
, thread
);
75 ("or" LISPOBJ_ASM_SUFFIX
" %0,%1"
82 clear_pseudo_atomic_interrupted(struct thread
*thread
)
84 if (get_pseudo_atomic_atomic(thread
))
85 lose("clear_pseudo_atomic_interrupted in pseudo atomic");
86 lispobj
*p
= SymbolValueAddress(PSEUDO_ATOMIC_BITS
, thread
);
88 ("and" LISPOBJ_ASM_SUFFIX
" %0,%1"
94 #undef LISPOBJ_ASM_SUFFIX
96 #elif (defined(LISP_FEATURE_ARM) || defined LISP_FEATURE_ARM64) && !defined LISP_FEATURE_SB_THREAD
98 get_pseudo_atomic_atomic(struct thread
*thread
)
100 return SymbolValue(PSEUDO_ATOMIC_ATOMIC
, thread
) != NIL
;
104 set_pseudo_atomic_atomic(struct thread
*thread
)
106 SetSymbolValue(PSEUDO_ATOMIC_ATOMIC
, PSEUDO_ATOMIC_ATOMIC
, thread
);
110 clear_pseudo_atomic_atomic(struct thread
*thread
)
112 SetSymbolValue(PSEUDO_ATOMIC_ATOMIC
, NIL
, thread
);
116 get_pseudo_atomic_interrupted(struct thread
*thread
)
118 return SymbolValue(PSEUDO_ATOMIC_INTERRUPTED
, thread
) != 0;
122 set_pseudo_atomic_interrupted(struct thread
*thread
)
124 SetSymbolValue(PSEUDO_ATOMIC_INTERRUPTED
, do_pending_interrupt
, thread
);
128 clear_pseudo_atomic_interrupted(struct thread
*thread
)
130 SetSymbolValue(PSEUDO_ATOMIC_INTERRUPTED
, 0, 0);
133 #elif defined(LISP_FEATURE_GENCGC)
135 /* FIXME: Are these async signal safe? Compiler reordering? */
137 #if !defined LISP_FEATURE_ARM && !defined LISP_FEATURE_ARM64
138 #define set_alloc_pointer(value) \
139 (dynamic_space_free_pointer = \
141 ((value) | (((uword_t)dynamic_space_free_pointer) & LOWTAG_MASK))))
143 #define get_alloc_pointer() \
144 ((uword_t) dynamic_space_free_pointer & ~LOWTAG_MASK)
147 #ifdef LISP_FEATURE_SB_THREAD
148 #define get_pseudo_atomic_atomic(thread) \
149 ((thread)->pseudo_atomic_bits & flag_PseudoAtomic)
150 #define set_pseudo_atomic_atomic(thread) \
151 ((thread)->pseudo_atomic_bits |= flag_PseudoAtomic)
152 #define clear_pseudo_atomic_atomic(thread) \
153 ((thread)->pseudo_atomic_bits &= ~flag_PseudoAtomic)
154 #define get_pseudo_atomic_interrupted(thread) \
155 ((thread)->pseudo_atomic_bits & flag_PseudoAtomicInterrupted)
156 #define set_pseudo_atomic_interrupted(thread) \
157 ((thread)->pseudo_atomic_bits |= flag_PseudoAtomicInterrupted)
158 #define clear_pseudo_atomic_interrupted(thread) \
159 ((thread)->pseudo_atomic_bits &= ~flag_PseudoAtomicInterrupted)
161 #define get_pseudo_atomic_atomic(thread) \
162 ((uword_t)dynamic_space_free_pointer & flag_PseudoAtomic)
163 #define set_pseudo_atomic_atomic(thread) \
164 (dynamic_space_free_pointer \
165 = (lispobj*) ((uword_t)dynamic_space_free_pointer | flag_PseudoAtomic))
166 #define clear_pseudo_atomic_atomic(thread) \
167 (dynamic_space_free_pointer \
168 = (lispobj*) ((uword_t) dynamic_space_free_pointer & ~flag_PseudoAtomic))
169 #define get_pseudo_atomic_interrupted(thread) \
170 ((uword_t) dynamic_space_free_pointer & flag_PseudoAtomicInterrupted)
171 #define clear_pseudo_atomic_interrupted(thread) \
172 (dynamic_space_free_pointer \
173 = (lispobj*) ((uword_t) dynamic_space_free_pointer & ~flag_PseudoAtomicInterrupted))
174 #define set_pseudo_atomic_interrupted(thread) \
175 (dynamic_space_free_pointer \
176 = (lispobj*) ((uword_t) dynamic_space_free_pointer | flag_PseudoAtomicInterrupted))
181 #if defined LISP_FEATURE_ARM || defined LISP_FEATURE_ARM64
182 #define set_alloc_pointer(value) \
183 SetSymbolValue(ALLOCATION_POINTER, value, 0)
184 #define get_alloc_pointer() \
185 SymbolValue(ALLOCATION_POINTER, 0)
187 #endif /* PSEUDO_ATOMIC_H */