Use https links in user-facing startup and error messages
[ghc.git] / rts / Sparks.h
1 /* -----------------------------------------------------------------------------
2 *
3 * (c) The GHC Team, 2000-2009
4 *
5 * Sparking support for PAR and THREADED_RTS versions of the RTS.
6 *
7 * ---------------------------------------------------------------------------*/
8
9 #pragma once
10
11 #include "WSDeque.h"
12
13 #include "BeginPrivate.h"
14
15 /* typedef for SparkPool in RtsTypes.h */
16
17 /* Stats on spark creation/conversion */
18 typedef struct {
19 StgWord created;
20 StgWord dud;
21 StgWord overflowed;
22 StgWord converted;
23 StgWord gcd;
24 StgWord fizzled;
25 } SparkCounters;
26
27 #if defined(THREADED_RTS)
28
29 typedef WSDeque SparkPool;
30
31 // Initialisation
32 SparkPool *allocSparkPool (void);
33
34 // Take a spark from the "write" end of the pool. Can be called
35 // by the pool owner only.
36 INLINE_HEADER StgClosure* reclaimSpark(SparkPool *pool);
37
38 // Returns True if the spark pool is empty (can give a false positive
39 // if the pool is almost empty).
40 INLINE_HEADER bool looksEmpty(SparkPool* deque);
41
42 INLINE_HEADER StgClosure * tryStealSpark (SparkPool *pool);
43 INLINE_HEADER bool fizzledSpark (StgClosure *);
44
45 void freeSparkPool (SparkPool *pool);
46 void createSparkThread (Capability *cap);
47 void traverseSparkQueue(evac_fn evac, void *user, Capability *cap);
48 void pruneSparkQueue (Capability *cap);
49
50 INLINE_HEADER void discardSparks (SparkPool *pool);
51 INLINE_HEADER long sparkPoolSize (SparkPool *pool);
52
53 /* -----------------------------------------------------------------------------
54 * PRIVATE below here
55 * -------------------------------------------------------------------------- */
56
57 INLINE_HEADER StgClosure* reclaimSpark(SparkPool *pool)
58 {
59 return popWSDeque(pool);
60 }
61
62 INLINE_HEADER bool looksEmpty(SparkPool* deque)
63 {
64 return looksEmptyWSDeque(deque);
65 }
66
67 INLINE_HEADER long sparkPoolSize (SparkPool *pool)
68 {
69 return dequeElements(pool);
70 }
71
72 INLINE_HEADER void discardSparks (SparkPool *pool)
73 {
74 discardElements(pool);
75 }
76
77 /* ----------------------------------------------------------------------------
78 *
79 * tryStealSpark: try to steal a spark from a Capability.
80 *
81 * Returns either:
82 * (a) a useful spark;
83 * (b) a fizzled spark (use fizzledSpark to check);
84 * (c) or NULL if the pool was empty, and can occasionally return NULL
85 * if there was a race with another thread stealing from the same
86 * pool. In this case, try again later.
87 *
88 -------------------------------------------------------------------------- */
89
90 INLINE_HEADER StgClosure * tryStealSpark (SparkPool *pool)
91 {
92 return stealWSDeque_(pool);
93 // use the no-loopy version, stealWSDeque_(), since if we get a
94 // spurious NULL here the caller may want to try stealing from
95 // other pools before trying again.
96 }
97
98 INLINE_HEADER bool fizzledSpark (StgClosure *spark)
99 {
100 return (GET_CLOSURE_TAG(spark) != 0 || !closure_SHOULD_SPARK(spark));
101 }
102
103 #endif // THREADED_RTS
104
105 #include "EndPrivate.h"