don't make -ddump-if-trace imply -no-recomp
[ghc-hetmet.git] / includes / SMPClosureOps.h
1 /* ----------------------------------------------------------------------------
2  *
3  * (c) The GHC Team, 2005
4  *
5  * Macros for THREADED_RTS support
6  *
7  * -------------------------------------------------------------------------- */
8
9 #ifndef SMPCLOSUREOPS_H
10 #define SMPCLOSUREOPS_H
11
12 #if defined(THREADED_RTS)
13
14 /* -----------------------------------------------------------------------------
15  * Locking/unlocking closures
16  *
17  * This is used primarily in the implementation of MVars.
18  * -------------------------------------------------------------------------- */
19
20 #define SPIN_COUNT 4000
21
22 #ifdef KEEP_LOCKCLOSURE
23 // We want a callable copy of lockClosure() so that we can refer to it
24 // from .cmm files compiled using the native codegen.
25 extern StgInfoTable *lockClosure(StgClosure *p);
26 INLINE_ME
27 #else
28 INLINE_HEADER
29 #endif
30 StgInfoTable *
31 lockClosure(StgClosure *p)
32 {
33     StgWord info;
34     do {
35         nat i = 0;
36         do {
37             info = xchg((P_)(void *)&p->header.info, (W_)&stg_WHITEHOLE_info);
38             if (info != (W_)&stg_WHITEHOLE_info) return (StgInfoTable *)info;
39         } while (++i < SPIN_COUNT);
40         yieldThread();
41     } while (1);
42 }
43
44 INLINE_HEADER void
45 unlockClosure(StgClosure *p, const StgInfoTable *info)
46 {
47     // This is a strictly ordered write, so we need a write_barrier():
48     write_barrier();
49     p->header.info = info;
50 }
51
52 #else /* !THREADED_RTS */
53
54 INLINE_HEADER StgInfoTable *
55 lockClosure(StgClosure *p)
56 { return (StgInfoTable *)p->header.info; }
57
58 INLINE_HEADER void
59 unlockClosure(StgClosure *p STG_UNUSED, const StgInfoTable *info STG_UNUSED)
60 { /* nothing */ }
61
62 #endif /* THREADED_RTS */
63
64 // Handy specialised versions of lockClosure()/unlockClosure()
65 INLINE_HEADER void lockTSO(StgTSO *tso)
66 { lockClosure((StgClosure *)tso); }
67
68 INLINE_HEADER void unlockTSO(StgTSO *tso)
69 { unlockClosure((StgClosure*)tso, (const StgInfoTable *)&stg_TSO_info); }
70
71 #endif /* SMPCLOSUREOPS_H */