SMP.h 1.21 KB
Newer Older
1
2
/* ----------------------------------------------------------------------------
 *
3
 * (c) The GHC Team, 2005
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 *
 * Macros for SMP support
 *
 * -------------------------------------------------------------------------- */

#ifndef SMP_H
#define SMP_H

/* SMP is currently not compatible with the following options:
 *
 *      INTERPRETER
 *      PROFILING
 *      TICKY_TICKY
 *      and unregisterised builds.
 */

#if defined(SMP)

22
#if  defined(PROFILING)  || defined(TICKY_TICKY)
23
24
25
26
27
28
29
#error Build options incompatible with SMP.
#endif

/* 
 * XCHG - the atomic exchange instruction.  Used for locking closures
 * during updates (see LOCK_CLOSURE below) and the MVar primops.
 */
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
INLINE_HEADER StgWord
xchg(StgPtr p, StgWord w)
{
    StgWord result;
    result = w;
    __asm__ __volatile__ (
 	  "xchgl %1,%0"
          :"+r" (result), "+m" (*p)
          : /* no input-only operands */
	);
    return result;
}

INLINE_HEADER StgInfoTable *
lockClosure(StgClosure *p)
{
    StgWord info;
#if 0
    do {
	info = xchg((P_)&p->header.info, (W_)&stg_WHITEHOLE_info);
	if (info != (W_)&stg_WHITEHOLE_info) return (StgInfoTable *)info;
	yieldThread();
    } while (1);
53
#else
54
    info = p->header.info;
55
#endif
56
}
57
58
59
60

#endif /* SMP */

#endif /* SMP_H */