X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=rts%2FCapability.c;h=02308d4c200c5b8a6893a3fa1cee2757de458cb4;hb=1a77fd719aef44c2f91a25ddf312c70651bce1f1;hp=fcfca3c733ece0a12a9a97aec377616947e2aefe;hpb=e8d7985d56595f6b8004546bedc41627ca70c528;p=ghc-hetmet.git diff --git a/rts/Capability.c b/rts/Capability.c index fcfca3c..02308d4 100644 --- a/rts/Capability.c +++ b/rts/Capability.c @@ -44,6 +44,21 @@ Capability *last_free_capability; /* GC indicator, in scope for the scheduler, init'ed to false */ volatile StgWord waiting_for_gc = 0; +/* Let foreign code get the current Capability -- assuming there is one! + * This is useful for unsafe foreign calls because they are called with + * the current Capability held, but they are not passed it. For example, + * see see the integer-gmp package which calls allocateLocal() in its + * stgAllocForGMP() function (which gets called by gmp functions). + * */ +Capability * rts_unsafeGetMyCapability (void) +{ +#if defined(THREADED_RTS) + return myTask()->cap; +#else + return &MainCapability; +#endif +} + #if defined(THREADED_RTS) STATIC_INLINE rtsBool globalWorkToDo (void) @@ -819,7 +834,7 @@ static void freeCapability (Capability *cap) { stgFree(cap->mut_lists); -#if defined(THREADED_RTS) || defined(PARALLEL_HASKELL) +#if defined(THREADED_RTS) freeSparkPool(cap->sparks); #endif }