X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=rts%2FTask.c;h=a15758c4f1cdb73f2862306f95d3c75de10fa551;hb=d8334d807812e40f67770ffc37608c0ce66f96b2;hp=9707251ca309bdccef7fc7b6298173398666fb9a;hpb=1991d6e39c1902c8877397622132bb7d6c7c5ebc;p=ghc-hetmet.git diff --git a/rts/Task.c b/rts/Task.c index 9707251..a15758c 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 * -------------------------------------------------------------------------- */ @@ -59,9 +63,12 @@ initTaskManager (void) if (!tasksInitialized) { taskCount = 0; tasksInitialized = 1; -#if defined(THREADED_RTS) && !defined(MYTASK_USE_TLV) +#if defined(THREADED_RTS) +#if !defined(MYTASK_USE_TLV) newThreadLocalKey(¤tTaskKey); #endif + initMutex(&all_tasks_mutex); +#endif } } @@ -71,7 +78,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 +93,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 +164,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 +188,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 +220,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 +295,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) { @@ -293,7 +305,7 @@ discardTasksExcept (Task *keep) } all_tasks = keep; keep->all_link = NULL; - RELEASE_LOCK(&sched_mutex); + RELEASE_LOCK(&all_tasks_mutex); } void @@ -336,6 +348,19 @@ workerTaskStop (Task *task) #endif +#ifdef DEBUG + +static void *taskId(Task *task) +{ +#ifdef THREADED_RTS + return (void *)task->id; +#else + return (void *)task; +#endif +} + +#endif + #if defined(THREADED_RTS) static void OSThreadProcAttr @@ -397,19 +422,19 @@ startWorkerTask (Capability *cap) RELEASE_LOCK(&task->lock); } +void +interruptWorkerTask (Task *task) +{ + ASSERT(osThreadId() != task->id); // seppuku not allowed + ASSERT(task->incall->suspended_tso); // use this only for FFI calls + interruptOSThread(task->id); + debugTrace(DEBUG_sched, "interrupted worker task %p", taskId(task)); +} + #endif /* THREADED_RTS */ #ifdef DEBUG -static void *taskId(Task *task) -{ -#ifdef THREADED_RTS - return (void *)task->id; -#else - return (void *)task; -#endif -} - void printAllTasks(void); void