X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=rts%2FCapability.c;h=02308d4c200c5b8a6893a3fa1cee2757de458cb4;hb=85df606a23117641682e19f3851099134e5f77a4;hp=c27733fa644ccc4b751351297db952c004fa554b;hpb=dd56e9ab4544e83d27532a8d9058140bfe81825c;p=ghc-hetmet.git diff --git a/rts/Capability.c b/rts/Capability.c index c27733f..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)