1 /* -----------------------------------------------------------------------------
3 * (c) The GHC Team, 2000-2006
5 * Sparking support for GRAN, PAR and THREADED_RTS versions of the RTS.
7 * ---------------------------------------------------------------------------*/
12 #if defined(PARALLEL_HASKELL)
13 #error Sparks.c using new internal structure, needs major overhaul!
16 /* typedef for SparkPool in RtsTypes.h */
18 #if defined(THREADED_RTS)
20 /* INVARIANTS, in this order: bottom/top consistent, reasonable size,
21 topBound consistent, space pointer, space accessible to us */
22 #define ASSERT_SPARK_POOL_INVARIANTS(p) \
23 ASSERT((p)->bottom >= (p)->top); \
24 ASSERT((p)->size > 0); \
25 ASSERT((p)->size > (p)->bottom - (p)->top); \
26 ASSERT((p)->topBound <= (p)->top); \
27 ASSERT((p)->elements != NULL); \
28 ASSERT(*((p)->elements) || 1); \
29 ASSERT(*((p)->elements - 1 + ((p)->size)) || 1);
31 // missing in old interface. Currently called by initSparkPools
33 SparkPool* initPool(StgWord size);
35 // special case: accessing our own pool, at the write end
36 // otherwise, we can always steal from our pool as the others do...
37 StgClosure* reclaimSpark(Capability *cap);
39 rtsBool looksEmpty(SparkPool* deque);
41 // rest: same as old interface
42 StgClosure * findSpark (Capability *cap);
43 void initSparkPools (void);
44 void freeSparkPool (SparkPool *pool);
45 void createSparkThread (Capability *cap, StgClosure *p);
46 void pruneSparkQueues (void);
47 void traverseSparkQueue(evac_fn evac, void *user, Capability *cap);
49 INLINE_HEADER void discardSparks (SparkPool *pool);
50 INLINE_HEADER nat sparkPoolSize (SparkPool *pool);
52 INLINE_HEADER void discardSparksCap (Capability *cap);
53 INLINE_HEADER nat sparkPoolSizeCap (Capability *cap);
54 INLINE_HEADER rtsBool emptySparkPoolCap (Capability *cap);
57 /* -----------------------------------------------------------------------------
59 * -------------------------------------------------------------------------- */
61 #if defined(PARALLEL_HASKELL) || defined(THREADED_RTS)
64 emptySparkPool (SparkPool *pool)
65 { return looksEmpty(pool); }
68 emptySparkPoolCap (Capability *cap)
69 { return looksEmpty(cap->sparks); }
72 sparkPoolSize (SparkPool *pool)
74 return (pool->bottom - pool->top);
78 sparkPoolSizeCap (Capability *cap)
79 { return sparkPoolSize(cap->sparks); }
82 discardSparks (SparkPool *pool)
84 pool->top = pool->bottom = 0;
88 discardSparksCap (Capability *cap)
89 { return discardSparks(cap->sparks); }