1 /* ----------------------------------------------------------------------------
2 * $Id: SMP.h,v 1.4 2002/02/04 20:10:47 sof Exp $
4 * (c) The GHC Team, 1999
6 * Macros for SMP support
8 * -------------------------------------------------------------------------- */
13 /* SMP is currently not compatible with the following options:
18 * and unregisterised builds.
23 #if defined(PROFILING) || defined(TICKY_TICKY)
24 #error Build options incompatible with SMP.
28 * CMPXCHG - this instruction is the standard "test & set". We use it
29 * for locking closures in the thunk and blackhole entry code. If the
30 * closure is already locked, or has an unexpected info pointer
31 * (because another thread is altering it in parallel), we just jump
32 * to the new entry point.
34 #if defined(i386_TARGET_ARCH) && defined(TABLES_NEXT_TO_CODE)
35 #define CMPXCHG(p, cmp, new) \
36 __asm__ __volatile__ ( \
37 "lock ; cmpxchg %1, %0\n" \
42 : "m" (p), "r" (new), "r" (cmp) \
46 * XCHG - the atomic exchange instruction. Used for locking closures
47 * during updates (see LOCK_CLOSURE below) and the MVar primops.
49 #define XCHG(reg, obj) \
50 __asm__ __volatile__ ( \
52 :"+r" (reg), "+m" (obj) \
53 : /* no input-only operands */ \
57 #error SMP macros not defined for this architecture
61 * LOCK_CLOSURE locks the specified closure, busy waiting for any
62 * existing locks to be cleared.
64 #define LOCK_CLOSURE(c) \
66 const StgInfoTable *__info; \
67 __info = &stg_WHITEHOLE_info; \
69 XCHG(__info,((StgClosure *)(c))->header.info); \
70 } while (__info == &stg_WHITEHOLE_info); \
74 #define LOCK_THUNK(__info) \
75 CMPXCHG(R1.cl->header.info, __info, &stg_WHITEHOLE_info);
79 #define LOCK_CLOSURE(c) /* nothing */
80 #define LOCK_THUNK(__info) /* nothing */