Add ASSERTs to all calls of nameModule
[ghc-hetmet.git] / rts / Sparks.h
1 /* -----------------------------------------------------------------------------
2  *
3  * (c) The GHC Team, 2000-2006
4  *
5  * Sparking support for GRAN, PAR and THREADED_RTS versions of the RTS.
6  * 
7  * ---------------------------------------------------------------------------*/
8
9 #ifndef SPARKS_H
10 #define SPARKS_H
11
12 #if defined(THREADED_RTS)
13 StgClosure * findSpark         (Capability *cap);
14 void         initSparkPools    (void);
15 void         freeSparkPool     (StgSparkPool *pool);
16 void         createSparkThread (Capability *cap, StgClosure *p);
17 void         pruneSparkQueues  (void);
18 void         traverseSparkQueue(evac_fn evac, void *user, Capability *cap);
19
20 INLINE_HEADER void     discardSparks  (StgSparkPool *pool);
21 INLINE_HEADER nat      sparkPoolSize  (StgSparkPool *pool);
22 INLINE_HEADER rtsBool  emptySparkPool (StgSparkPool *pool);
23
24 INLINE_HEADER void     discardSparksCap  (Capability *cap);
25 INLINE_HEADER nat      sparkPoolSizeCap  (Capability *cap);
26 INLINE_HEADER rtsBool  emptySparkPoolCap (Capability *cap);
27 #endif
28
29 /* -----------------------------------------------------------------------------
30  * PRIVATE below here
31  * -------------------------------------------------------------------------- */
32
33 #if defined(PARALLEL_HASKELL) || defined(THREADED_RTS)
34
35 INLINE_HEADER rtsBool
36 emptySparkPool (StgSparkPool *pool)
37 {
38     return (pool->hd == pool->tl);
39 }
40
41 INLINE_HEADER rtsBool
42 emptySparkPoolCap (Capability *cap) 
43 { return emptySparkPool(&cap->r.rSparks); }
44
45 INLINE_HEADER nat
46 sparkPoolSize (StgSparkPool *pool) 
47 {
48     if (pool->hd <= pool->tl) {
49         return (pool->tl - pool->hd);
50     } else {
51         return (pool->lim - pool->hd + pool->tl - pool->base);
52     }
53 }
54
55 INLINE_HEADER nat
56 sparkPoolSizeCap (Capability *cap) 
57 { return sparkPoolSize(&cap->r.rSparks); }
58
59 INLINE_HEADER void
60 discardSparks (StgSparkPool *pool)
61 {
62     pool->hd = pool->tl;
63 }
64
65 INLINE_HEADER void
66 discardSparksCap (Capability *cap) 
67 { return discardSparks(&cap->r.rSparks); }
68
69
70 #elif defined(THREADED_RTS) 
71
72 INLINE_HEADER rtsBool
73 emptySparkPoolCap (Capability *cap STG_UNUSED)
74 { return rtsTrue; }
75
76 #endif
77
78 #endif /* SPARKS_H */