From 36b55f46942a4cb38e23b1130885b5f82e4d6772 Mon Sep 17 00:00:00 2001 From: Michael Lotz Date: Sat, 26 Jan 2008 18:44:23 +0000 Subject: [PATCH] Don't panic in case a thread is not in the wait queue of a sem anymore. On SMP systems it can easily happen that the thread gets removed from the queue (when it times out for example) during the time we don't hold the sem lock. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23749 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/system/kernel/sem.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/system/kernel/sem.cpp b/src/system/kernel/sem.cpp index e93e05fff0..f61ff3156a 100644 --- a/src/system/kernel/sem.cpp +++ b/src/system/kernel/sem.cpp @@ -601,18 +601,21 @@ sem_interrupt_thread(struct thread *thread) } clear_thread_queue(&wakeupQueue); - if (remove_thread_from_sem(thread, &sSems[slot], &wakeupQueue, - B_INTERRUPTED, true) != B_OK) { - panic("sem_interrupt_thread: thread %ld not found in sem %ld's wait " - "queue\n", thread->id, thread->sem.blocking); - } + status_t result = remove_thread_from_sem(thread, &sSems[slot], + &wakeupQueue, B_INTERRUPTED, true); RELEASE_SEM_LOCK(sSems[slot]); + if (result != B_OK) { + // The thread is not in the wait queue anymore. Probably it just timed + // out before we locked the sem. + return result; + } + while ((thread = thread_dequeue(&wakeupQueue)) != NULL) scheduler_enqueue_in_run_queue(thread); - return B_NO_ERROR; + return B_OK; }