1 /* ----------------------------------------------------------------------------
3 * (c) The GHC Team, 1999
5 * Macros for SMP support
7 * -------------------------------------------------------------------------- */
12 /* SMP is currently not compatible with the following options:
17 * and unregisterised builds.
22 #if defined(PROFILING) || defined(TICKY_TICKY)
23 #error Build options incompatible with SMP.
27 * CMPXCHG - this instruction is the standard "test & set". We use it
28 * for locking closures in the thunk and blackhole entry code. If the
29 * closure is already locked, or has an unexpected info pointer
30 * (because another thread is altering it in parallel), we just jump
31 * to the new entry point.
33 #if defined(i386_HOST_ARCH) && defined(TABLES_NEXT_TO_CODE)
34 #define CMPXCHG(p, cmp, new) \
35 __asm__ __volatile__ ( \
36 "lock ; cmpxchg %1, %0\n" \
41 : "m" (p), "r" (new), "r" (cmp) \
45 * XCHG - the atomic exchange instruction. Used for locking closures
46 * during updates (see LOCK_CLOSURE below) and the MVar primops.
48 #define XCHG(reg, obj) \
49 __asm__ __volatile__ ( \
51 :"+r" (reg), "+m" (obj) \
52 : /* no input-only operands */ \
56 #error SMP macros not defined for this architecture
60 * LOCK_CLOSURE locks the specified closure, busy waiting for any
61 * existing locks to be cleared.
63 #define LOCK_CLOSURE(c) \
65 const StgInfoTable *__info; \
66 __info = &stg_WHITEHOLE_info; \
68 XCHG(__info,((StgClosure *)(c))->header.info); \
69 } while (__info == &stg_WHITEHOLE_info); \
73 #define LOCK_THUNK(__info) \
74 CMPXCHG(R1.cl->header.info, __info, &stg_WHITEHOLE_info);
78 #define LOCK_CLOSURE(c) /* nothing */
79 #define LOCK_THUNK(__info) /* nothing */