[project @ 2005-10-20 11:45:19 by simonmar]
[ghc-hetmet.git] / ghc / rts / Task.c
index 8e0a279..0d75df8 100644 (file)
@@ -28,7 +28,8 @@
 TaskInfo* taskTable;
 static nat taskTableSize;
 
-HashTable *taskHash; // maps OSThreadID to TaskInfo*
+// maps OSThreadID to TaskInfo*
+HashTable *taskHash;
 
 nat taskCount;
 static nat tasksRunning;
@@ -43,7 +44,12 @@ initTaskManager (void)
     static int initialized = 0;
 
     if (!initialized) {
+#if defined(SMP)
+       taskTableSize = stg_max(INIT_TASK_TABLE_SIZE, 
+                               RtsFlags.ParFlags.nNodes * 2);
+#else
        taskTableSize = INIT_TASK_TABLE_SIZE;
+#endif
        taskTable = stgMallocBytes( taskTableSize * sizeof(TaskInfo),
                                    "initTaskManager");
     
@@ -62,44 +68,23 @@ initTaskManager (void)
 static void
 expandTaskTable (void)
 {
+    nat i;
+
     taskTableSize *= 2;
     taskTable = stgReallocBytes(taskTable, taskTableSize * sizeof(TaskInfo),
                                "expandTaskTable");
+
+    /* Have to update the hash table now... */
+    for (i = 0; i < taskCount; i++) {
+       removeHashTable( taskHash, taskTable[i].id, NULL );
+       insertHashTable( taskHash, taskTable[i].id, &taskTable[i] );
+    }
 }
 
 void
 stopTaskManager (void)
 {
-    nat i;
-
     IF_DEBUG(scheduler, sched_belch("stopping task manager, %d tasks still running", tasksRunning));
-    for (i = 1000; i > 0; i--) {
-       if (tasksRunning == 0) {
-           IF_DEBUG(scheduler, sched_belch("all tasks stopped"));
-           return;
-       }
-       IF_DEBUG(scheduler, sched_belch("yielding"));
-       prodWorker();
-       yieldThread();
-    }
-    IF_DEBUG(scheduler, sched_belch("%d tasks still running, exiting anyway", tasksRunning));
-
-    /* 
-       OLD CODE follows:
-    */
-#if old_code
-    /* Send 'em all a SIGHUP.  That should shut 'em up. */
-    awaitDeath = taskCount==0 ? 0 : taskCount-1;
-    for (i = 0; i < taskCount; i++) {
-       /* don't cancel the thread running this piece of code. */
-       if ( taskTable[i].id != tid ) {
-           pthread_kill(taskTable[i].id,SIGTERM);
-       }
-    }
-    while (awaitDeath > 0) {
-       sched_yield();
-    }
-#endif // old_code
 }