X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=rts%2FSparks.h;h=cffe99dd390f82c0dccad5b1911c3b84c25826f2;hp=dbbf268988a98969b6e19180715494ed23a6c4ff;hb=HEAD;hpb=cf9650f2a1690c04051c716124bb0350adc74ae7 diff --git a/rts/Sparks.h b/rts/Sparks.h index dbbf268..cffe99d 100644 --- a/rts/Sparks.h +++ b/rts/Sparks.h @@ -1,6 +1,6 @@ /* ----------------------------------------------------------------------------- * - * (c) The GHC Team, 2000-2006 + * (c) The GHC Team, 2000-2009 * * Sparking support for GRAN, PAR and THREADED_RTS versions of the RTS. * @@ -9,85 +9,62 @@ #ifndef SPARKS_H #define SPARKS_H -#if defined(PARALLEL_HASKELL) -#error Sparks.c using new internal structure, needs major overhaul! -#endif +#include "WSDeque.h" + +#include "BeginPrivate.h" /* typedef for SparkPool in RtsTypes.h */ #if defined(THREADED_RTS) -/* INVARIANTS, in this order: bottom/top consistent, reasonable size, - topBound consistent, space pointer, space accessible to us */ -#define ASSERT_SPARK_POOL_INVARIANTS(p) \ - ASSERT((p)->bottom >= (p)->top); \ - ASSERT((p)->size > 0); \ - ASSERT((p)->size > (p)->bottom - (p)->top); \ - ASSERT((p)->topBound <= (p)->top); \ - ASSERT((p)->elements != NULL); \ - ASSERT(*((p)->elements) || 1); \ - ASSERT(*((p)->elements - 1 + ((p)->size)) || 1); - -// missing in old interface. Currently called by initSparkPools -// internally. -SparkPool* initPool(StgWord size); - -// special case: accessing our own pool, at the write end -// otherwise, we can always steal from our pool as the others do... -StgClosure* reclaimSpark(Capability *cap); - -rtsBool looksEmpty(SparkPool* deque); - -// rest: same as old interface -StgClosure * findSpark (Capability *cap); -void initSparkPools (void); +typedef WSDeque SparkPool; + +// Initialisation +void initSparkPools (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); + +StgClosure * tryStealSpark (Capability *cap); void freeSparkPool (SparkPool *pool); -void createSparkThread (Capability *cap, StgClosure *p); -void pruneSparkQueues (void); +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 nat sparkPoolSize (SparkPool *pool); - -INLINE_HEADER void discardSparksCap (Capability *cap); -INLINE_HEADER nat sparkPoolSizeCap (Capability *cap); -INLINE_HEADER rtsBool emptySparkPoolCap (Capability *cap); -#endif +INLINE_HEADER void discardSparks (SparkPool *pool); +INLINE_HEADER long sparkPoolSize (SparkPool *pool); /* ----------------------------------------------------------------------------- * PRIVATE below here * -------------------------------------------------------------------------- */ -#if defined(PARALLEL_HASKELL) || defined(THREADED_RTS) - -INLINE_HEADER rtsBool -emptySparkPool (SparkPool *pool) -{ return looksEmpty(pool); } - -INLINE_HEADER rtsBool -emptySparkPoolCap (Capability *cap) -{ return looksEmpty(cap->sparks); } +INLINE_HEADER StgClosure* reclaimSpark(SparkPool *pool) +{ + return popWSDeque(pool); +} -INLINE_HEADER nat -sparkPoolSize (SparkPool *pool) +INLINE_HEADER rtsBool looksEmpty(SparkPool* deque) { - return (pool->bottom - pool->top); + return looksEmptyWSDeque(deque); } -INLINE_HEADER nat -sparkPoolSizeCap (Capability *cap) -{ return sparkPoolSize(cap->sparks); } +INLINE_HEADER long sparkPoolSize (SparkPool *pool) +{ + return dequeElements(pool); +} -INLINE_HEADER void -discardSparks (SparkPool *pool) +INLINE_HEADER void discardSparks (SparkPool *pool) { - pool->top = pool->bottom = 0; + discardElements(pool); } -INLINE_HEADER void -discardSparksCap (Capability *cap) -{ return discardSparks(cap->sparks); } +#endif // THREADED_RTS -#endif +#include "EndPrivate.h" #endif /* SPARKS_H */