[project @ 2001-10-31 10:34:29 by simonmar]
[ghc-hetmet.git] / ghc / rts / Schedule.c
index 425551c..35b9b79 100644 (file)
@@ -1,5 +1,5 @@
 /* ---------------------------------------------------------------------------
- * $Id: Schedule.c,v 1.97 2001/07/23 17:23:19 simonmar Exp $
+ * $Id: Schedule.c,v 1.104 2001/10/31 10:34:29 simonmar Exp $
  *
  * (c) The GHC Team, 1998-2000
  *
@@ -74,6 +74,7 @@
 //@node Includes, Variables and Data structures, Main scheduling code, Main scheduling code
 //@subsection Includes
 
+#include "PosixSource.h"
 #include "Rts.h"
 #include "SchedAPI.h"
 #include "RtsUtils.h"
@@ -444,6 +445,7 @@ schedule( void )
          pthread_cond_broadcast(&m->wakeup);
          break;
        case ThreadKilled:
+         if (m->ret) *(m->ret) = NULL;
          *prev = m->link;
          if (was_interrupted) {
            m->stat = Interrupted;
@@ -476,6 +478,7 @@ schedule( void )
          m->stat = Success;
          return;
        } else {
+         if (m->ret) { *(m->ret) = NULL; };
          if (was_interrupted) {
            m->stat = Interrupted;
          } else {
@@ -526,6 +529,13 @@ schedule( void )
     }
 #endif /* SMP */
 
+    /* check for signals each time around the scheduler */
+#ifndef mingw32_TARGET_OS
+    if (signals_pending()) {
+      startSignalHandlers();
+    }
+#endif
+
     /* Check whether any waiting threads need to be woken up.  If the
      * run queue is empty, and there are no other tasks running, we
      * can wait indefinitely for something to happen.
@@ -543,13 +553,6 @@ schedule( void )
     /* we can be interrupted while waiting for I/O... */
     if (interrupted) continue;
 
-    /* check for signals each time around the scheduler */
-#ifndef mingw32_TARGET_OS
-    if (signals_pending()) {
-      start_signal_handlers();
-    }
-#endif
-
     /* 
      * Detect deadlock: when we have no threads to run, there are no
      * threads waiting on I/O or sleeping, and all the other tasks are
@@ -581,12 +584,14 @@ schedule( void )
                StgMainThread *m = main_threads;
 #ifdef SMP
                for (; m != NULL; m = m->link) {
+                   deleteThread(m->tso);
                    m->ret = NULL;
                    m->stat = Deadlock;
                    pthread_cond_broadcast(&m->wakeup);
                }
                main_threads = NULL;
 #else
+               deleteThread(m->tso);
                m->ret = NULL;
                m->stat = Deadlock;
                main_threads = m->link;
@@ -1394,6 +1399,16 @@ int cmp_thread(const StgTSO *tso1, const StgTSO *tso2)
 }
 
 /* ---------------------------------------------------------------------------
+ * Fetching the ThreadID from an StgTSO.
+ *
+ * This is used in the implementation of Show for ThreadIds.
+ * ------------------------------------------------------------------------ */
+int rts_getThreadId(const StgTSO *tso) 
+{
+  return tso->id;
+}
+
+/* ---------------------------------------------------------------------------
    Create a new thread.
 
    The new thread starts with the given stack size.  Before the
@@ -2092,7 +2107,8 @@ take_off_run_queue(StgTSO *tso) {
        KH @ 25/10/99
 */
 
-static void GetRoots(evac_fn evac)
+static void
+GetRoots(evac_fn evac)
 {
   StgMainThread *m;
 
@@ -2920,7 +2936,7 @@ raiseAsync(StgTSO *tso, StgClosure *exception)
   }
 
   while (1) {
-    int words = ((P_)su - (P_)sp) - 1;
+    nat words = ((P_)su - (P_)sp) - 1;
     nat i;
     StgAP_UPD * ap;