From d92565096840c6248cc435ebfc662432a3b5c252 Mon Sep 17 00:00:00 2001 From: Michael Lotz Date: Fri, 25 Jan 2008 13:55:17 +0000 Subject: [PATCH] Apply the same logic as in r23731 to all other places in the semaphore code where threads are enqueued into the run queue. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23733 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/system/kernel/sem.cpp | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/system/kernel/sem.cpp b/src/system/kernel/sem.cpp index 40a22f82e2..28f217c01b 100644 --- a/src/system/kernel/sem.cpp +++ b/src/system/kernel/sem.cpp @@ -320,7 +320,12 @@ sem_timeout(timer *data) GRAB_THREAD_LOCK(); // put the threads in the run q here to make sure we dont deadlock in sem_interrupt_thread while ((thread = thread_dequeue(&wakeupQueue)) != NULL) { - scheduler_enqueue_in_run_queue(thread); + if (thread->state == B_THREAD_RUNNING) + thread->next_state = B_THREAD_READY; + else { + thread->state = thread->next_state = B_THREAD_READY; + scheduler_enqueue_in_run_queue(thread); + } } RELEASE_THREAD_LOCK(); @@ -610,7 +615,12 @@ sem_interrupt_thread(struct thread *thread) RELEASE_SEM_LOCK(sSems[slot]); while ((thread = thread_dequeue(&wakeupQueue)) != NULL) { - scheduler_enqueue_in_run_queue(thread); + if (thread->state == B_THREAD_RUNNING) + thread->next_state = B_THREAD_READY; + else { + thread->state = thread->next_state = B_THREAD_READY; + scheduler_enqueue_in_run_queue(thread); + } } return B_NO_ERROR; @@ -643,7 +653,6 @@ remove_thread_from_sem(struct thread *thread, struct sem_entry *sem, thread->sem.count -= delta; if (thread->sem.count <= 0) { thread = thread_dequeue(&sem->u.used.queue); - thread->state = thread->next_state = B_THREAD_READY; thread_enqueue(thread, queue); } sem->u.used.count -= delta; @@ -763,7 +772,6 @@ delete_sem(sem_id id) // free any threads waiting for this semaphore while ((thread = thread_dequeue(&sSems[slot].u.used.queue)) != NULL) { - thread->state = B_THREAD_READY; thread->sem.acquire_status = B_BAD_SEM_ID; thread->sem.count = 0; thread_enqueue(thread, &releaseQueue); @@ -785,7 +793,12 @@ delete_sem(sem_id id) if (releasedThreads > 0) { GRAB_THREAD_LOCK(); while ((thread = thread_dequeue(&releaseQueue)) != NULL) { - scheduler_enqueue_in_run_queue(thread); + if (thread->state == B_THREAD_RUNNING) + thread->next_state = B_THREAD_READY; + else { + thread->state = thread->next_state = B_THREAD_READY; + scheduler_enqueue_in_run_queue(thread); + } } scheduler_reschedule(); RELEASE_THREAD_LOCK(); @@ -943,7 +956,12 @@ switch_sem_etc(sem_id semToBeReleased, sem_id id, int32 count, } RELEASE_SEM_LOCK(sSems[slot]); while ((thread = thread_dequeue(&wakeupQueue)) != NULL) { - scheduler_enqueue_in_run_queue(thread); + if (thread->state == B_THREAD_RUNNING) + thread->next_state = B_THREAD_READY; + else { + thread->state = thread->next_state = B_THREAD_READY; + scheduler_enqueue_in_run_queue(thread); + } } // fall through and reschedule since another thread with a higher priority may have been woken up } @@ -1093,7 +1111,7 @@ release_sem_etc(sem_id id, int32 count, uint32 flags) if (thread->state == B_THREAD_RUNNING) thread->next_state = B_THREAD_READY; else { - thread->state = B_THREAD_READY; + thread->state = thread->next_state = B_THREAD_READY; scheduler_enqueue_in_run_queue(thread); } }