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