/* ----------------------------------------------------------------------------
- * $Id: RtsAPI.c,v 1.48 2003/10/01 10:36:49 wolfgang Exp $
*
* (c) The GHC Team, 1998-2001
*
#include "PosixSource.h"
#include "Rts.h"
+#include "OSThreads.h"
#include "Storage.h"
#include "RtsAPI.h"
#include "SchedAPI.h"
#include "RtsFlags.h"
#include "RtsUtils.h"
#include "Prelude.h"
-#include "OSThreads.h"
#include "Schedule.h"
#include "Capability.h"
HaskellObj
rts_mkInt64 (HsInt64 i)
{
- long long *tmp;
+ llong *tmp;
StgClosure *p = (StgClosure *)allocate(CONSTR_sizeW(0,2));
SET_HDR(p, I64zh_con_info, CCS_SYSTEM);
- tmp = (long long*)&(p->payload[0]);
+ tmp = (llong*)&(p->payload[0]);
*tmp = (StgInt64)i;
return p;
}
HaskellObj
rts_mkWord64 (HsWord64 w)
{
- unsigned long long *tmp;
+ ullong *tmp;
StgClosure *p = (StgClosure *)allocate(CONSTR_sizeW(0,2));
/* see mk_Int8 comment */
SET_HDR(p, W64zh_con_info, CCS_SYSTEM);
- tmp = (unsigned long long*)&(p->payload[0]);
+ tmp = (ullong*)&(p->payload[0]);
*tmp = (StgWord64)w;
return p;
}
HaskellObj
rts_apply (HaskellObj f, HaskellObj arg)
{
- StgClosure *ap;
+ StgThunk *ap;
- ap = (StgClosure *)allocate(sizeofW(StgClosure) + 2);
+ ap = (StgThunk *)allocate(sizeofW(StgThunk) + 2);
SET_HDR(ap, (StgInfoTable *)&stg_ap_2_upd_info, CCS_SYSTEM);
ap->payload[0] = f;
ap->payload[1] = arg;
StgTSO* tso;
StgClosure *p, *r;
SchedulerStatus stat;
+ Capability *cap = rtsApiCapability;
+ rtsApiCapability = NULL;
p = (StgClosure *)deRefStablePtr(s);
tso = createStrictIOThread(RtsFlags.GcFlags.initialStkSize, p);
- stat = scheduleWaitThread(tso,&r,rtsApiCapability);
- rtsApiCapability = NULL;
+ stat = scheduleWaitThread(tso,&r,cap);
if (stat == Success && ret != NULL) {
ASSERT(r != NULL);
case Success:
return;
case Killed:
- prog_belch("%s: uncaught exception",site);
+ errorBelch("%s: uncaught exception",site);
stg_exit(EXIT_FAILURE);
case Interrupted:
- prog_belch("%s: interrupted", site);
+ errorBelch("%s: interrupted", site);
stg_exit(EXIT_FAILURE);
default:
- prog_belch("%s: Return code (%d) not ok",(site),(rc));
+ errorBelch("%s: Return code (%d) not ok",(site),(rc));
stg_exit(EXIT_FAILURE);
}
}
rts_lock()
{
#ifdef RTS_SUPPORTS_THREADS
- ACQUIRE_LOCK(&sched_mutex);
-
- // we request to get the capability immediately, in order to
- // a) stop other threads from using allocate()
- // b) wake the current worker thread from awaitEvent()
- // (so that a thread started by rts_eval* will start immediately)
- grabReturnCapability(&sched_mutex,&rtsApiCapability);
+ ACQUIRE_LOCK(&sched_mutex);
- // In the RTS hasn't been entered yet,
- // start a RTS task.
- // If there is already a task available (waiting for the work capability),
- // this will do nothing.
- startSchedulerTask();
+ // we request to get the capability immediately, in order to
+ // a) stop other threads from using allocate()
+ // b) wake the current worker thread from awaitEvent()
+ // (so that a thread started by rts_eval* will start immediately)
+ waitForReturnCapability(&sched_mutex,&rtsApiCapability);
+#else
+ grabCapability(&rtsApiCapability);
#endif
}
rts_unlock()
{
#ifdef RTS_SUPPORTS_THREADS
- if(rtsApiCapability)
+ if (rtsApiCapability) {
releaseCapability(rtsApiCapability);
+ }
rtsApiCapability = NULL;
RELEASE_LOCK(&sched_mutex);
#endif