From daf0126bb2795492377c8cc25c183b06cb6d66d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Mon, 26 Jan 2004 02:01:46 +0000 Subject: [PATCH] alarm_event() has sent the signal to the currently running thread instead of the one that issues the alarm - it now does an ugly cast to get the real thread structure. It would be nice if we had an additional user parameter to a timer event. Thanks to Travis for reporting this one! git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6310 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kernel/core/signal.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/kernel/core/signal.c b/src/kernel/core/signal.c index 8d9f832dc0..6261eb0251 100644 --- a/src/kernel/core/signal.c +++ b/src/kernel/core/signal.c @@ -6,16 +6,16 @@ #include #include -#include #include #include #include #include #include #include -#include #include +#include +#include #define SIGNAL_TO_MASK(signal) (1LL << (signal - 1)) @@ -245,7 +245,16 @@ sigaction(int signal, const struct sigaction *act, struct sigaction *oact) static int32 alarm_event(timer *t) { - send_signal_etc(thread_get_current_thread()->id, SIGALRM, B_DO_NOT_RESCHEDULE); + // The hook can be called from any context, but we have to + // deliver the signal to the thread that originally called + // set_alarm(). + // Since thread->alarm is this timer structure, we can just + // cast it back - ugly but it works for now + struct thread *thread = (struct thread *)((uint8 *)t - offsetof(struct thread, alarm)); + // ToDo: investigate adding one user parameter to the timer structure to fix this hack + + dprintf("alarm_event: thread = %p\n", thread); + send_signal_etc(thread->id, SIGALRM, B_DO_NOT_RESCHEDULE); return B_INVOKE_SCHEDULER; } @@ -260,6 +269,8 @@ set_alarm(bigtime_t time, uint32 mode) ASSERT(B_ONE_SHOT_RELATIVE_ALARM == B_ONE_SHOT_RELATIVE_TIMER); // just to be sure no one changes the headers some day + dprintf("set_alarm: thread = %p\n", thread); + if (thread->alarm.period) rv = (bigtime_t)thread->alarm.entry.key - system_time();