From 23884ae0250a1731e1f880ec0d971c4f32c88eea Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sat, 20 Sep 2008 12:38:27 +0000 Subject: [PATCH] Introduced a callback field in the thread structure. It can be set in an interrupt handler and will be executed right before returning from the interrupt. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27648 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/kernel/thread_types.h | 3 +++ src/system/kernel/arch/x86/arch_int.c | 9 +++++++++ src/system/kernel/thread.cpp | 2 ++ 3 files changed, 14 insertions(+) diff --git a/headers/private/kernel/thread_types.h b/headers/private/kernel/thread_types.h index f6489145a0..9506c1ae31 100644 --- a/headers/private/kernel/thread_types.h +++ b/headers/private/kernel/thread_types.h @@ -309,6 +309,9 @@ struct thread { bigtime_t kernel_time; bigtime_t last_time; + void (*post_interrupt_callback)(void*); + void* post_interrupt_data; + // architecture dependant section struct arch_thread arch_info; }; diff --git a/src/system/kernel/arch/x86/arch_int.c b/src/system/kernel/arch/x86/arch_int.c index b362ce63b5..ef14c5c73f 100644 --- a/src/system/kernel/arch/x86/arch_int.c +++ b/src/system/kernel/arch/x86/arch_int.c @@ -891,6 +891,7 @@ hardware_interrupt(struct iframe* frame) int32 vector = frame->vector - ARCH_INTERRUPT_BASE; bool levelTriggered = false; int ret; + struct thread* thread = thread_get_current_thread(); if (sCurrentPIC->is_spurious_interrupt(vector)) { TRACE(("got spurious interrupt at vector %ld\n", vector)); @@ -916,6 +917,14 @@ hardware_interrupt(struct iframe* frame) RELEASE_THREAD_LOCK(); restore_interrupts(state); + } else if (thread->post_interrupt_callback != NULL) { + void (*callback)(void*) = thread->post_interrupt_callback; + void* data = thread->post_interrupt_data; + + thread->post_interrupt_callback = NULL; + thread->post_interrupt_data = NULL; + + callback(data); } } diff --git a/src/system/kernel/thread.cpp b/src/system/kernel/thread.cpp index dcfa0640df..2ed6d50cbd 100644 --- a/src/system/kernel/thread.cpp +++ b/src/system/kernel/thread.cpp @@ -248,6 +248,8 @@ create_thread_struct(struct thread *inthread, const char *name, thread->exit.signal = 0; list_init(&thread->exit.waiters); thread->select_infos = NULL; + thread->post_interrupt_callback = NULL; + thread->post_interrupt_data = NULL; sprintf(temp, "thread_%ld_retcode_sem", thread->id); thread->exit.sem = create_sem(0, temp);