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