From 83d563cb9ede0ba792836e529b1e2929db926355 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Sun, 19 Sep 2010 00:29:05 +0000 Subject: Interruptible FFI calls with pthread_kill and CancelSynchronousIO. v4 This is patch that adds support for interruptible FFI calls in the form of a new foreign import keyword 'interruptible', which can be used instead of 'safe' or 'unsafe'. Interruptible FFI calls act like safe FFI calls, except that the worker thread they run on may be interrupted. Internally, it replaces BlockedOnCCall_NoUnblockEx with BlockedOnCCall_Interruptible, and changes the behavior of the RTS to not modify the TSO_ flags on the event of an FFI call from a thread that was interruptible. It also modifies the bytecode format for foreign call, adding an extra Word16 to indicate interruptibility. The semantics of interruption vary from platform to platform, but the intent is that any blocking system calls are aborted with an error code. This is most useful for making function calls to system library functions that support interrupting. There is no support for pre-Vista Windows. There is a partner testsuite patch which adds several tests for this functionality. --- rts/Task.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'rts/Task.c') diff --git a/rts/Task.c b/rts/Task.c index e93d60d86f..f26785a1be 100644 --- a/rts/Task.c +++ b/rts/Task.c @@ -409,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 -- cgit v1.2.1