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