merge upstream HEAD
[ghc-hetmet.git] / rts / Sparks.h
1 /* -----------------------------------------------------------------------------
2  *
3  * (c) The GHC Team, 2000-2009
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 #include "WSDeque.h"
13
14 #include "BeginPrivate.h"
15
16 /* typedef for SparkPool in RtsTypes.h */
17
18 #if defined(THREADED_RTS)
19
20 typedef WSDeque SparkPool;
21
22 // Initialisation
23 void initSparkPools (void);
24
25 // Take a spark from the "write" end of the pool.  Can be called
26 // by the pool owner only.
27 INLINE_HEADER StgClosure* reclaimSpark(SparkPool *pool);
28
29 // Returns True if the spark pool is empty (can give a false positive
30 // if the pool is almost empty).
31 INLINE_HEADER rtsBool looksEmpty(SparkPool* deque);
32
33 StgClosure * tryStealSpark     (Capability *cap);
34 void         freeSparkPool     (SparkPool *pool);
35 void         createSparkThread (Capability *cap);
36 void         traverseSparkQueue(evac_fn evac, void *user, Capability *cap);
37 void         pruneSparkQueue   (Capability *cap);
38
39 INLINE_HEADER void discardSparks  (SparkPool *pool);
40 INLINE_HEADER long sparkPoolSize  (SparkPool *pool);
41
42 /* -----------------------------------------------------------------------------
43  * PRIVATE below here
44  * -------------------------------------------------------------------------- */
45
46 INLINE_HEADER StgClosure* reclaimSpark(SparkPool *pool)
47 {
48     return popWSDeque(pool);
49 }
50
51 INLINE_HEADER rtsBool looksEmpty(SparkPool* deque)
52 {
53     return looksEmptyWSDeque(deque);
54 }
55
56 INLINE_HEADER long sparkPoolSize (SparkPool *pool) 
57
58     return dequeElements(pool);
59 }
60
61 INLINE_HEADER void discardSparks (SparkPool *pool)
62 {
63     discardElements(pool);
64 }
65
66 #endif // THREADED_RTS
67
68 #include "EndPrivate.h"
69
70 #endif /* SPARKS_H */