Improve handling of -fdph-* flags
[ghc.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 EXTERN_INLINE StgInfoTable *lockClosure(StgClosure *p);
13 EXTERN_INLINE void unlockClosure(StgClosure *p, const StgInfoTable *info);
14
15 #if defined(THREADED_RTS)
16
17 /* -----------------------------------------------------------------------------
18 * Locking/unlocking closures
19 *
20 * This is used primarily in the implementation of MVars.
21 * -------------------------------------------------------------------------- */
22
23 #define SPIN_COUNT 4000
24
25 // We want a callable copy of lockClosure() so that we can refer to it
26 // from .cmm files compiled using the native codegen.
27 EXTERN_INLINE StgInfoTable *lockClosure(StgClosure *p)
28 {
29 StgWord info;
30 do {
31 nat i = 0;
32 do {
33 info = xchg((P_)(void *)&p->header.info, (W_)&stg_WHITEHOLE_info);
34 if (info != (W_)&stg_WHITEHOLE_info) return (StgInfoTable *)info;
35 } while (++i < SPIN_COUNT);
36 yieldThread();
37 } while (1);
38 }
39
40 EXTERN_INLINE void unlockClosure(StgClosure *p, const StgInfoTable *info)
41 {
42 // This is a strictly ordered write, so we need a write_barrier():
43 write_barrier();
44 p->header.info = info;
45 }
46
47 #else /* !THREADED_RTS */
48
49 EXTERN_INLINE StgInfoTable *
50 lockClosure(StgClosure *p)
51 { return (StgInfoTable *)p->header.info; }
52
53 EXTERN_INLINE void
54 unlockClosure(StgClosure *p STG_UNUSED, const StgInfoTable *info STG_UNUSED)
55 { /* nothing */ }
56
57 #endif /* THREADED_RTS */
58
59 // Handy specialised versions of lockClosure()/unlockClosure()
60 EXTERN_INLINE void lockTSO(StgTSO *tso);
61 EXTERN_INLINE void lockTSO(StgTSO *tso)
62 { lockClosure((StgClosure *)tso); }
63
64 EXTERN_INLINE void unlockTSO(StgTSO *tso);
65 EXTERN_INLINE void unlockTSO(StgTSO *tso)
66 { unlockClosure((StgClosure*)tso, (const StgInfoTable *)&stg_TSO_info); }
67
68 #endif /* SMPCLOSUREOPS_H */