1 /* ----------------------------------------------------------------------------
2 * $Id: SMP.h,v 1.1 1999/11/02 15:05:52 simonmar 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(INTERPRETER) \
24 || defined(PROFILING) \
25 || defined(TICKY_TICKY)
26 #error Build options incompatible with SMP.
30 * CMPXCHG - this instruction is the standard "test & set". We use it
31 * for locking closures in the thunk and blackhole entry code. If the
32 * closure is already locked, or has an unexpected info pointer
33 * (because another thread is altering it in parallel), we just jump
34 * to the new entry point.
36 #if defined(i386_TARGET_ARCH) && defined(TABLES_NEXT_TO_CODE)
37 #define CMPXCHG(p, cmp, new) \
38 __asm__ __volatile__ ( \
39 "lock ; cmpxchg %1, %0\n" \
44 : "m" (p), "r" (new), "r" (cmp) \
48 * XCHG - the atomic exchange instruction. Used for locking closures
49 * during updates (see LOCK_CLOSURE below) and the MVar primops.
51 #define XCHG(reg, obj) \
52 __asm__ __volatile__ ( \
54 :"+r" (reg), "+m" (obj) \
55 : /* no input-only operands */ \
59 #error SMP macros not defined for this architecture
63 * LOCK_CLOSURE locks the specified closure, busy waiting for any
64 * existing locks to be cleared.
66 #define LOCK_CLOSURE(c) \
68 const StgInfoTable *__info; \
69 __info = &WHITEHOLE_info; \
71 XCHG(__info,((StgClosure *)(c))->header.info); \
72 } while (__info == &WHITEHOLE_info); \
76 #define LOCK_THUNK(__info) \
77 CMPXCHG(R1.cl->header.info, __info, &WHITEHOLE_info);
79 #define ACQUIRE_LOCK(mutex) pthread_mutex_lock(mutex);
80 #define RELEASE_LOCK(mutex) pthread_mutex_unlock(mutex);
84 #define LOCK_CLOSURE(c) /* nothing */
85 #define LOCK_THUNK(__info) /* nothing */
86 #define ACQUIRE_LOCK(mutex) /* nothing */
87 #define RELEASE_LOCK(mutex) /* nothing */