X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Frts%2FCapability.c;fp=ghc%2Frts%2FCapability.c;h=7aacc24c6ffc4e70581e6daee5dc02a4b8d45fd2;hb=677c63455e46b5536800a2dc2db70b64cc802266;hp=cb921d127f532c01d0e309374b08d14d56407e5f;hpb=f9f5235fce1fb043b0738d86190a4e50386e5dcc;p=ghc-hetmet.git diff --git a/ghc/rts/Capability.c b/ghc/rts/Capability.c index cb921d1..7aacc24 100644 --- a/ghc/rts/Capability.c +++ b/ghc/rts/Capability.c @@ -142,6 +142,10 @@ initCapability( Capability *cap, nat i ) cap->f.stgGCEnter1 = (F_)__stg_gc_enter_1; cap->f.stgGCFun = (F_)__stg_gc_fun; + + cap->mut_lists = stgMallocBytes(sizeof(bdescr *) * + RtsFlags.GcFlags.generations, + "initCapability"); } /* --------------------------------------------------------------------------- @@ -572,6 +576,29 @@ shutdownCapability (Capability *cap, Task *task) // list are both empty. } +/* ---------------------------------------------------------------------------- + * tryGrabCapability + * + * Attempt to gain control of a Capability if it is free. + * + * ------------------------------------------------------------------------- */ + +rtsBool +tryGrabCapability (Capability *cap, Task *task) +{ + if (cap->running_task != NULL) return rtsFalse; + ACQUIRE_LOCK(&cap->lock); + if (cap->running_task != NULL) { + RELEASE_LOCK(&cap->lock); + return rtsFalse; + } + task->cap = cap; + cap->running_task = task; + RELEASE_LOCK(&cap->lock); + return rtsTrue; +} + + #endif /* THREADED_RTS */