Improve the newSpark dud test by using the pointer tag bits
[ghc.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 INLINE_HEADER rtsBool fizzledSpark (StgClosure *);
35
36 void freeSparkPool (SparkPool *pool);
37 void createSparkThread (Capability *cap);
38 void traverseSparkQueue(evac_fn evac, void *user, Capability *cap);
39 void pruneSparkQueue (Capability *cap);
40
41 INLINE_HEADER void discardSparks (SparkPool *pool);
42 INLINE_HEADER long sparkPoolSize (SparkPool *pool);
43
44 /* -----------------------------------------------------------------------------
45 * PRIVATE below here
46 * -------------------------------------------------------------------------- */
47
48 INLINE_HEADER StgClosure* reclaimSpark(SparkPool *pool)
49 {
50 return popWSDeque(pool);
51 }
52
53 INLINE_HEADER rtsBool looksEmpty(SparkPool* deque)
54 {
55 return looksEmptyWSDeque(deque);
56 }
57
58 INLINE_HEADER long sparkPoolSize (SparkPool *pool)
59 {
60 return dequeElements(pool);
61 }
62
63 INLINE_HEADER void discardSparks (SparkPool *pool)
64 {
65 discardElements(pool);
66 }
67
68 INLINE_HEADER rtsBool fizzledSpark (StgClosure *spark)
69 {
70 return (GET_CLOSURE_TAG(spark) != 0 || !closure_SHOULD_SPARK(spark));
71 }
72
73 #endif // THREADED_RTS
74
75 #include "EndPrivate.h"
76
77 #endif /* SPARKS_H */