Author: bonefish Date: 2011-05-11 15:33:10 +0200 (Wed, 11 May 2011) New Revision: 41439 Changeset: https://dev.haiku-os.org/changeset/41439 Modified: haiku/branches/developer/bonefish/signals/src/system/kernel/sem.cpp Log: Replaced uses of gThreadSpinlock by gSchedulerLock. Modified: haiku/branches/developer/bonefish/signals/src/system/kernel/sem.cpp =================================================================== --- haiku/branches/developer/bonefish/signals/src/system/kernel/sem.cpp 2011-05-11 13:17:35 UTC (rev 41438) +++ haiku/branches/developer/bonefish/signals/src/system/kernel/sem.cpp 2011-05-11 13:33:10 UTC (rev 41439) @@ -329,12 +329,12 @@ sem.u.used.select_infos = NULL; // free any threads waiting for this semaphore - GRAB_THREAD_LOCK(); + SpinLocker schedulerLocker(gSchedulerLock); while (queued_thread* entry = sem.queue.RemoveHead()) { entry->queued = false; thread_unblock_locked(entry->thread, B_BAD_SEM_ID); } - RELEASE_THREAD_LOCK(); + schedulerLocker.Unlock(); int32 id = sem.id; sem.id = -1; @@ -394,9 +394,9 @@ char* name; uninit_sem_locked(sSems[slot], &name); - GRAB_THREAD_LOCK(); + SpinLocker schedulerLocker(gSchedulerLock); scheduler_reschedule_if_necessary_locked(); - RELEASE_THREAD_LOCK(); + schedulerLocker.Unlock(); restore_interrupts(state); @@ -641,10 +641,11 @@ // We're done with this entry. We only have to check, if other threads // need unblocking, too. - // Now see if more threads need to be woken up. We get the thread lock for - // that time, so the blocking state of threads won't change. We need that - // lock anyway when unblocking a thread. - GRAB_THREAD_LOCK(); + // Now see if more threads need to be woken up. We get the scheduler lock + // for that time, so the blocking state of threads won't change (due to + // interruption or timeout). We need that lock anyway when unblocking a + // thread. + SpinLocker schedulerLocker(gSchedulerLock); while ((entry = sem->queue.Head()) != NULL) { if (thread_is_blocked(entry->thread)) { @@ -665,7 +666,7 @@ entry->queued = false; } - RELEASE_THREAD_LOCK(); + schedulerLocker.Unlock(); // select notification, if the semaphore is now acquirable if (sem->u.used.count > 0) @@ -849,13 +850,13 @@ semToBeReleased = -1; } - GRAB_THREAD_LOCK(); + SpinLocker schedulerLocker(gSchedulerLock); status_t acquireStatus = timeout == B_INFINITE_TIMEOUT ? thread_block_locked(thread) : thread_block_with_timeout_locked(flags, timeout); - RELEASE_THREAD_LOCK(); + schedulerLocker.Unlock(); GRAB_SEM_LOCK(sSems[slot]); // If we're still queued, this means the acquiration failed, and we @@ -967,7 +968,9 @@ flags |= B_RELEASE_IF_WAITING_ONLY; } - SpinLocker threadLocker(gThreadSpinlock); + // Grab the scheduler lock, so thread_is_blocked() is reliable (due to + // possible interruptions or timeouts, it wouldn't be otherwise). + SpinLocker schedulerLocker(gSchedulerLock); while (count > 0) { queued_thread* entry = sSems[slot].queue.Head(); @@ -1004,7 +1007,7 @@ entry->queued = false; } - threadLocker.Unlock(); + schedulerLocker.Unlock(); if (sSems[slot].u.used.count > 0) notify_sem_select_events(&sSems[slot], B_EVENT_ACQUIRE_SEMAPHORE); @@ -1013,7 +1016,7 @@ // been told not to. if ((flags & B_DO_NOT_RESCHEDULE) == 0) { semLocker.Unlock(); - threadLocker.Lock(); + schedulerLocker.Lock(); scheduler_reschedule_if_necessary_locked(); }