X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fruntime%2Fpseudo-atomic.h;h=230e3e85e22b17a1c91728823e0cac27138d0cef;hb=b30f21a9cf8366ec88022e84c698f1d8d45e885e;hp=df5e900950e8cffcf1a89f366e70c981e2156999;hpb=4023b1bec2412344e5eea4a33cd85dd662149c67;p=sbcl.git diff --git a/src/runtime/pseudo-atomic.h b/src/runtime/pseudo-atomic.h index df5e900..230e3e8 100644 --- a/src/runtime/pseudo-atomic.h +++ b/src/runtime/pseudo-atomic.h @@ -22,35 +22,80 @@ SetSymbolValue(ALLOCATION_POINTER, value, 0) #define get_alloc_pointer() \ SymbolValue(ALLOCATION_POINTER, 0) -#define get_binding_stack_pointer(thread) \ - SymbolValue(BINDING_STACK_POINTER, thread) -#define get_pseudo_atomic_atomic(thread) \ - (fixnum_value(SymbolValue(PSEUDO_ATOMIC_BITS, thread) & make_fixnum(1))) -#define set_pseudo_atomic_atomic(thread) \ - { \ - lispobj bits = SymbolValue(PSEUDO_ATOMIC_BITS, thread); \ - SetSymbolValue(PSEUDO_ATOMIC_BITS, bits | make_fixnum(1), thread); \ - } -#define clear_pseudo_atomic_atomic(thread) \ - { \ - lispobj bits = SymbolValue(PSEUDO_ATOMIC_BITS, thread); \ - SetSymbolValue(PSEUDO_ATOMIC_BITS, bits & ~make_fixnum(1), thread); \ - } -#define get_pseudo_atomic_interrupted(thread) \ - (fixnum_value(SymbolValue(PSEUDO_ATOMIC_BITS, thread) & make_fixnum(2))) -#define clear_pseudo_atomic_interrupted(thread) \ - { \ - lispobj bits = SymbolValue(PSEUDO_ATOMIC_BITS, thread); \ - SetSymbolValue(PSEUDO_ATOMIC_BITS, bits & ~make_fixnum(2), thread); \ - } -#define set_pseudo_atomic_interrupted(thread) \ - { \ - lispobj bits = SymbolValue(PSEUDO_ATOMIC_BITS, thread); \ - SetSymbolValue(PSEUDO_ATOMIC_BITS, bits | make_fixnum(2), thread); \ - } +#if defined(LISP_FEATURE_X86) +#define LISPOBJ_ASM_SUFFIX "l" +#elif defined(LISP_FEATURE_X86_64) +#define LISPOBJ_ASM_SUFFIX "q" +#endif + +static inline int +get_pseudo_atomic_atomic(struct thread *thread) +{ + return SymbolValue(PSEUDO_ATOMIC_BITS, thread) & (~1); +} + +static inline void +set_pseudo_atomic_atomic(struct thread *thread) +{ + lispobj *p = SymbolValueAddress(PSEUDO_ATOMIC_BITS, thread); + if (*p) + lose("set_pseudo_atomic_atomic: pseudo atomic bits is %d.", *p); + __asm__ __volatile__ + ("or" LISPOBJ_ASM_SUFFIX " %0,%1" + : + : "g" (~1), "m" (*p) + : "memory"); +} + +static inline void +clear_pseudo_atomic_atomic(struct thread *thread) +{ + lispobj *p = SymbolValueAddress(PSEUDO_ATOMIC_BITS, thread); + __asm__ __volatile__ + ("and" LISPOBJ_ASM_SUFFIX " %0,%1" + : + : "g" (1), "m" (*p) + : "memory"); +} -#elif defined(LISP_FEATURE_PPC) && defined(LISP_FEATURE_GENCGC) +static inline int +get_pseudo_atomic_interrupted(struct thread *thread) +{ + return SymbolValue(PSEUDO_ATOMIC_BITS, thread) & 1; +} + +static inline void +set_pseudo_atomic_interrupted(struct thread *thread) +{ + if (!get_pseudo_atomic_atomic(thread)) + lose("set_pseudo_atomic_interrupted not in pseudo atomic"); + lispobj *p = SymbolValueAddress(PSEUDO_ATOMIC_BITS, thread); + __asm__ __volatile__ + ("or" LISPOBJ_ASM_SUFFIX " %0,%1" + : + : "g" (1), "m" (*p) + : "memory"); +} + +static inline void +clear_pseudo_atomic_interrupted(struct thread *thread) +{ + if (get_pseudo_atomic_atomic(thread)) + lose("clear_pseudo_atomic_interrupted in pseudo atomic"); + lispobj *p = SymbolValueAddress(PSEUDO_ATOMIC_BITS, thread); + __asm__ __volatile__ + ("and" LISPOBJ_ASM_SUFFIX " %0,%1" + : + : "g" (~1), "m" (*p) + : "memory"); +} + +#undef LISPOBJ_SUFFIX + +#elif defined(LISP_FEATURE_GENCGC) + +/* FIXME: Are these async signal safe? Compiler reordering? */ #define set_alloc_pointer(value) \ (dynamic_space_free_pointer = \ @@ -59,8 +104,21 @@ #define get_alloc_pointer() \ ((unsigned long) dynamic_space_free_pointer & ~LOWTAG_MASK) -#define get_binding_stack_pointer(thread) \ - (current_binding_stack_pointer) + +#ifdef LISP_FEATURE_SB_THREAD +#define get_pseudo_atomic_atomic(thread) \ + ((thread)->pseudo_atomic_bits & flag_PseudoAtomic) +#define set_pseudo_atomic_atomic(thread) \ + ((thread)->pseudo_atomic_bits |= flag_PseudoAtomic) +#define clear_pseudo_atomic_atomic(thread) \ + ((thread)->pseudo_atomic_bits &= ~flag_PseudoAtomic) +#define get_pseudo_atomic_interrupted(thread) \ + ((thread)->pseudo_atomic_bits & flag_PseudoAtomicInterrupted) +#define set_pseudo_atomic_interrupted(thread) \ + ((thread)->pseudo_atomic_bits |= flag_PseudoAtomicInterrupted) +#define clear_pseudo_atomic_interrupted(thread) \ + ((thread)->pseudo_atomic_bits &= ~flag_PseudoAtomicInterrupted) +#else #define get_pseudo_atomic_atomic(thread) \ ((unsigned long)dynamic_space_free_pointer & flag_PseudoAtomic) #define set_pseudo_atomic_atomic(thread) \ @@ -77,6 +135,7 @@ #define set_pseudo_atomic_interrupted(thread) \ (dynamic_space_free_pointer \ = (lispobj*) ((unsigned long) dynamic_space_free_pointer | flag_PseudoAtomicInterrupted)) +#endif #endif