[project @ 2004-10-03 17:13:34 by panne]
[ghc-hetmet.git] / ghc / rts / RtsAPI.c
index 2052f3d..4ca1225 100644 (file)
@@ -1,5 +1,4 @@
 /* ----------------------------------------------------------------------------
- * $Id: RtsAPI.c,v 1.50 2003/11/12 17:49:08 sof Exp $
  *
  * (c) The GHC Team, 1998-2001
  *
@@ -431,11 +430,12 @@ rts_evalStableIO (HsStablePtr s, /*out*/HsStablePtr *ret)
     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);
@@ -479,13 +479,13 @@ rts_checkSchedStatus ( char* site, SchedulerStatus rc )
     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);
     }
 }
@@ -494,13 +494,13 @@ void
 rts_lock()
 {
 #ifdef RTS_SUPPORTS_THREADS
-       ACQUIRE_LOCK(&sched_mutex);
+    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);
+    // 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);
 #endif
 }
 
@@ -508,8 +508,9 @@ void
 rts_unlock()
 {
 #ifdef RTS_SUPPORTS_THREADS
-    if(rtsApiCapability)
+    if (rtsApiCapability) {
        releaseCapability(rtsApiCapability);
+    }
     rtsApiCapability = NULL;
     RELEASE_LOCK(&sched_mutex);
 #endif