Interruptible FFI calls with pthread_kill and CancelSynchronousIO. v4
[ghc-hetmet.git] / rts / Task.c
index 8a289be..f26785a 100644 (file)
@@ -63,8 +63,10 @@ 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(&currentTaskKey);
+#endif
         initMutex(&all_tasks_mutex);
 #endif
     }
@@ -407,6 +409,15 @@ 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 %lu", task->id);
+}
+
 #endif /* THREADED_RTS */
 
 #ifdef DEBUG