Kind sig for toplevel family decls is optional
[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(GRAN)
13 StgInt newSpark (StgRegTable *reg, StgClosure *p);
14 #endif
15
16 #if defined(PARALLEL_HASKELL) || defined(THREADED_RTS)
17 StgClosure * findSpark         (Capability *cap);
18 void         initSparkPools    (void);
19 void         markSparkQueue    (evac_fn evac);
20 void         createSparkThread (Capability *cap, StgClosure *p);
21
22 INLINE_HEADER void     discardSparks  (StgSparkPool *pool);
23 INLINE_HEADER nat      sparkPoolSize  (StgSparkPool *pool);
24 INLINE_HEADER rtsBool  emptySparkPool (StgSparkPool *pool);
25
26 INLINE_HEADER void     discardSparksCap  (Capability *cap);
27 INLINE_HEADER nat      sparkPoolSizeCap  (Capability *cap);
28 INLINE_HEADER rtsBool  emptySparkPoolCap (Capability *cap);
29 #endif
30
31 #if defined(PARALLEL_HASKELL)
32 StgTSO      *activateSpark (rtsSpark spark) ;
33 rtsBool      add_to_spark_queue( StgClosure *closure, StgSparkPool *pool );
34 void         markSparkQueue( void );
35 nat          spark_queue_len( StgSparkPool *pool );
36 void         disposeSpark( StgClosure *spark );
37 #endif
38
39 #if defined(GRAN)
40 void      findLocalSpark (rtsEvent *event, rtsBool *found_res, rtsSparkQ *spark_res);
41 rtsBool   activateSpark (rtsEvent *event, rtsSparkQ spark);
42 rtsSpark *newSpark(StgClosure *node, nat name, nat gran_info, 
43                    nat size_info, nat par_info, nat local);
44 void      add_to_spark_queue(rtsSpark *spark);
45 rtsSpark *delete_from_sparkq (rtsSpark *spark, PEs p, rtsBool dispose_too);
46 void      disposeSpark(rtsSpark *spark);
47 void      disposeSparkQ(rtsSparkQ spark);
48 void      print_spark(rtsSpark *spark);
49 void      print_sparkq(PEs proc);
50 void      print_sparkq_stats(void);
51 nat       spark_queue_len(PEs proc);
52 void      markSparkQueue(void);
53 #endif
54
55 /* -----------------------------------------------------------------------------
56  * PRIVATE below here
57  * -------------------------------------------------------------------------- */
58
59 #if defined(PARALLEL_HASKELL) || defined(THREADED_RTS)
60
61 INLINE_HEADER rtsBool
62 emptySparkPool (StgSparkPool *pool)
63 {
64     return (pool->hd == pool->tl);
65 }
66
67 INLINE_HEADER rtsBool
68 emptySparkPoolCap (Capability *cap) 
69 { return emptySparkPool(&cap->r.rSparks); }
70
71 INLINE_HEADER nat
72 sparkPoolSize (StgSparkPool *pool) 
73 {
74     if (pool->hd <= pool->tl) {
75         return (pool->hd - pool->tl);
76     } else {
77         return (pool->lim - pool->hd + pool->tl - pool->base);
78     }
79 }
80
81 INLINE_HEADER nat
82 sparkPoolSizeCap (Capability *cap) 
83 { return sparkPoolSize(&cap->r.rSparks); }
84
85 INLINE_HEADER void
86 discardSparks (StgSparkPool *pool)
87 {
88     pool->hd = pool->tl;
89 }
90
91 INLINE_HEADER void
92 discardSparksCap (Capability *cap) 
93 { return discardSparks(&cap->r.rSparks); }
94
95
96 #elif defined(THREADED_RTS) 
97
98 INLINE_HEADER rtsBool
99 emptySparkPoolCap (Capability *cap STG_UNUSED)
100 { return rtsTrue; }
101
102 #endif
103
104 #endif /* SPARKS_H */