1 /* ----------------------------------------------------------------------------
3 * (c) The GHC Team, 2005
5 * Macros for THREADED_RTS support
7 * -------------------------------------------------------------------------- */
9 #ifndef RTS_STORAGE_SMPCLOSUREOPS_H
10 #define RTS_STORAGE_SMPCLOSUREOPS_H
14 #define unlockClosure(ptr,info) \
15 prim %write_barrier() []; \
16 StgHeader_info(ptr) = info;
20 EXTERN_INLINE StgInfoTable *lockClosure(StgClosure *p);
21 EXTERN_INLINE void unlockClosure(StgClosure *p, const StgInfoTable *info);
23 #if defined(THREADED_RTS)
25 /* -----------------------------------------------------------------------------
26 * Locking/unlocking closures
28 * This is used primarily in the implementation of MVars.
29 * -------------------------------------------------------------------------- */
31 // We want a callable copy of lockClosure() so that we can refer to it
32 // from .cmm files compiled using the native codegen.
33 EXTERN_INLINE StgInfoTable *lockClosure(StgClosure *p)
39 info = xchg((P_)(void *)&p->header.info, (W_)&stg_WHITEHOLE_info);
40 if (info != (W_)&stg_WHITEHOLE_info) return (StgInfoTable *)info;
41 } while (++i < SPIN_COUNT);
46 EXTERN_INLINE void unlockClosure(StgClosure *p, const StgInfoTable *info)
48 // This is a strictly ordered write, so we need a write_barrier():
50 p->header.info = info;
53 #else /* !THREADED_RTS */
55 EXTERN_INLINE StgInfoTable *
56 lockClosure(StgClosure *p)
57 { return (StgInfoTable *)p->header.info; }
60 unlockClosure(StgClosure *p STG_UNUSED, const StgInfoTable *info STG_UNUSED)
63 #endif /* THREADED_RTS */
65 // Handy specialised versions of lockClosure()/unlockClosure()
66 EXTERN_INLINE void lockTSO(StgTSO *tso);
67 EXTERN_INLINE void lockTSO(StgTSO *tso)
68 { lockClosure((StgClosure *)tso); }
70 EXTERN_INLINE void unlockTSO(StgTSO *tso);
71 EXTERN_INLINE void unlockTSO(StgTSO *tso)
72 { unlockClosure((StgClosure*)tso, (const StgInfoTable *)&stg_TSO_info); }
74 #endif /* CMINUSMINUS */
76 #endif /* RTS_STORAGE_SMPCLOSUREOPS_H */