X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=rts%2FTask.c;h=8a289be0078f8a4d68af8b532a8ef9b219a74145;hb=ddec0ec0a7772c434f2c7b4d284e9280067ed26b;hp=e2f363b3210d83fc9e6220b7a2a09fd4e9a89947;hpb=12cfec943127f0c81e1ffa1ca5ce46e888e3027c;p=ghc-hetmet.git diff --git a/rts/Task.c b/rts/Task.c index e2f363b..8a289be 100644 --- a/rts/Task.c +++ b/rts/Task.c @@ -24,7 +24,7 @@ #endif // Task lists and global counters. -// Locks required: sched_mutex. +// Locks required: all_tasks_mutex. Task *all_tasks = NULL; static nat taskCount; static int tasksInitialized = 0; @@ -33,6 +33,10 @@ static void freeTask (Task *task); static Task * allocTask (void); static Task * newTask (rtsBool); +#if defined(THREADED_RTS) +static Mutex all_tasks_mutex; +#endif + /* ----------------------------------------------------------------------------- * Remembering the current thread's Task * -------------------------------------------------------------------------- */ @@ -61,6 +65,7 @@ initTaskManager (void) tasksInitialized = 1; #if defined(THREADED_RTS) && !defined(MYTASK_USE_TLV) newThreadLocalKey(¤tTaskKey); + initMutex(&all_tasks_mutex); #endif } } @@ -71,7 +76,7 @@ freeTaskManager (void) Task *task, *next; nat tasksRunning = 0; - ASSERT_LOCK_HELD(&sched_mutex); + ACQUIRE_LOCK(&all_tasks_mutex); for (task = all_tasks; task != NULL; task = next) { next = task->all_link; @@ -86,7 +91,11 @@ freeTaskManager (void) tasksRunning); all_tasks = NULL; + + RELEASE_LOCK(&all_tasks_mutex); + #if defined(THREADED_RTS) && !defined(MYTASK_USE_TLV) + closeMutex(&all_tasks_mutex); freeThreadLocalKey(¤tTaskKey); #endif @@ -153,8 +162,7 @@ newTask (rtsBool worker) task->cap = NULL; task->worker = worker; task->stopped = rtsFalse; - task->stat = NoStatus; - task->ret = NULL; + task->running_finalizers = rtsFalse; task->n_spare_incalls = 0; task->spare_incalls = NULL; task->incall = NULL; @@ -178,14 +186,14 @@ newTask (rtsBool worker) task->next = NULL; - ACQUIRE_LOCK(&sched_mutex); + ACQUIRE_LOCK(&all_tasks_mutex); task->all_link = all_tasks; all_tasks = task; taskCount++; - RELEASE_LOCK(&sched_mutex); + RELEASE_LOCK(&all_tasks_mutex); return task; } @@ -210,6 +218,8 @@ newInCall (Task *task) incall->task = task; incall->suspended_tso = NULL; incall->suspended_cap = NULL; + incall->stat = NoStatus; + incall->ret = NULL; incall->next = NULL; incall->prev = NULL; incall->prev_stack = task->incall; @@ -283,7 +293,7 @@ discardTasksExcept (Task *keep) Task *task, *next; // Wipe the task list, except the current Task. - ACQUIRE_LOCK(&sched_mutex); + ACQUIRE_LOCK(&all_tasks_mutex); for (task = all_tasks; task != NULL; task=next) { next = task->all_link; if (task != keep) { @@ -292,7 +302,8 @@ discardTasksExcept (Task *keep) } } all_tasks = keep; - RELEASE_LOCK(&sched_mutex); + keep->all_link = NULL; + RELEASE_LOCK(&all_tasks_mutex); } void