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