[project @ 2002-02-16 00:30:05 by sof]
[ghc-hetmet.git] / ghc / rts / Schedule.c
index 1f8d06b..01c97fc 100644 (file)
@@ -1,5 +1,5 @@
 /* ---------------------------------------------------------------------------
- * $Id: Schedule.c,v 1.127 2002/02/15 17:49:23 sof Exp $
+ * $Id: Schedule.c,v 1.130 2002/02/16 00:30:05 sof Exp $
  *
  * (c) The GHC Team, 1998-2000
  *
@@ -1344,7 +1344,9 @@ schedule( void )
 #if defined(RTS_SUPPORTS_THREADS)
       IF_DEBUG(scheduler,sched_belch("doing GC"));
 #endif
+      RELEASE_LOCK(&sched_mutex);
       GarbageCollect(GetRoots,rtsFalse);
+      ACQUIRE_LOCK(&sched_mutex);
       ready_to_gc = rtsFalse;
 #ifdef SMP
       broadcastCondition(&gc_pending_cond);
@@ -1428,7 +1430,7 @@ void deleteAllThreads ( void )
  * ------------------------------------------------------------------------- */
    
 StgInt
-suspendThread( StgRegTable *reg )
+suspendThread( StgRegTable *reg, rtsBool concCall )
 {
   nat tok;
   Capability *cap;
@@ -1457,7 +1459,7 @@ suspendThread( StgRegTable *reg )
   /* Hand back capability */
   releaseCapability(cap);
   
-#if defined(RTS_SUPPORTS_THREADS) && !defined(SMP)
+#if defined(RTS_SUPPORTS_THREADS)
   /* Preparing to leave the RTS, so ensure there's a native thread/task
      waiting to take over.
      
@@ -1466,23 +1468,30 @@ suspendThread( StgRegTable *reg )
      there's no need to create a new task).
   */
   IF_DEBUG(scheduler, sched_belch("worker thread (%d): leaving RTS", tok));
-  startTask(taskStart);
+  if (concCall) {
+    startTask(taskStart);
+  }
 #endif
 
+  /* Other threads _might_ be available for execution; signal this */
   THREAD_RUNNABLE();
   RELEASE_LOCK(&sched_mutex);
   return tok; 
 }
 
 StgRegTable *
-resumeThread( StgInt tok )
+resumeThread( StgInt tok, rtsBool concCall )
 {
   StgTSO *tso, **prev;
   Capability *cap;
 
 #if defined(RTS_SUPPORTS_THREADS)
   /* Wait for permission to re-enter the RTS with the result. */
-  grabReturnCapability(&sched_mutex, &cap);
+  if ( concCall ) {
+    grabReturnCapability(&sched_mutex, &cap);
+  } else {
+    grabCapability(&cap);
+  }
 #else
   grabCapability(&cap);
 #endif