MERGE: Fix Windows DEP violations (bug #885)
[ghc-hetmet.git] / rts / Task.c
index a03ed87..0e51dbf 100644 (file)
@@ -15,6 +15,7 @@
 #include "Capability.h"
 #include "Stats.h"
 #include "RtsFlags.h"
+#include "Storage.h"
 #include "Schedule.h"
 #include "Hash.h"
 #include "Trace.h"
@@ -67,21 +68,35 @@ initTaskManager (void)
 void
 stopTaskManager (void)
 {
-    Task *task, *next;
+    Task *task;
 
     debugTrace(DEBUG_sched, 
               "stopping task manager, %d tasks still running",
               tasksRunning);
 
     ACQUIRE_LOCK(&sched_mutex);
-    for (task = task_free_list; task != NULL; task = next) {
-        next = task->next;
-        stgFree(task);
+    for (task = task_free_list; task != NULL; task = task->next) {
 #if defined(THREADED_RTS)
         closeCondition(&task->cond);
         closeMutex(&task->lock);
 #endif
     }
+    RELEASE_LOCK(&sched_mutex);
+}
+
+
+void
+freeTaskManager (void)
+{
+    Task *task, *next;
+
+    debugTrace(DEBUG_sched, "freeing task manager");
+
+    ACQUIRE_LOCK(&sched_mutex);
+    for (task = task_free_list; task != NULL; task = next) {
+        next = task->next;
+        stgFree(task);
+    }
     task_free_list = NULL;
     RELEASE_LOCK(&sched_mutex);
 }
@@ -283,7 +298,8 @@ startWorkerTask (Capability *cap,
 
   r = createOSThread(&tid, (OSThreadProc *)taskStart, task);
   if (r != 0) {
-    barf("startTask: Can't create new task");
+    sysErrorBelch("failed to create OS thread");
+    stg_exit(EXIT_FAILURE);
   }
 
   debugTrace(DEBUG_sched, "new worker task (taskCount: %d)", taskCount);