Condition variable waiters are queued in descending priority order, so

there is no need to wake all waiters to assure that the highest priority
thread is run.  As the semaphore code is written, there was no correctness
problem, but the change improves sem_post() performance.

Pointed out by:	deischen
This commit is contained in:
jasone 2001-05-18 00:36:05 +00:00
parent 6bc2d961bf
commit cbe4cb8f95
3 changed files with 6 additions and 27 deletions

View File

@ -226,15 +226,8 @@ _sem_post(sem_t *sem)
pthread_mutex_lock(&(*sem)->lock);
(*sem)->count++;
if ((*sem)->nwaiters > 0) {
/*
* We must use pthread_cond_broadcast() rather than
* pthread_cond_signal() in order to assure that the highest
* priority thread is run by the scheduler, since
* pthread_cond_signal() signals waiting threads in FIFO order.
*/
pthread_cond_broadcast(&(*sem)->gtzero);
}
if ((*sem)->nwaiters > 0)
pthread_cond_signal(&(*sem)->gtzero);
pthread_mutex_unlock(&(*sem)->lock);

View File

@ -226,15 +226,8 @@ _sem_post(sem_t *sem)
pthread_mutex_lock(&(*sem)->lock);
(*sem)->count++;
if ((*sem)->nwaiters > 0) {
/*
* We must use pthread_cond_broadcast() rather than
* pthread_cond_signal() in order to assure that the highest
* priority thread is run by the scheduler, since
* pthread_cond_signal() signals waiting threads in FIFO order.
*/
pthread_cond_broadcast(&(*sem)->gtzero);
}
if ((*sem)->nwaiters > 0)
pthread_cond_signal(&(*sem)->gtzero);
pthread_mutex_unlock(&(*sem)->lock);

View File

@ -226,15 +226,8 @@ _sem_post(sem_t *sem)
pthread_mutex_lock(&(*sem)->lock);
(*sem)->count++;
if ((*sem)->nwaiters > 0) {
/*
* We must use pthread_cond_broadcast() rather than
* pthread_cond_signal() in order to assure that the highest
* priority thread is run by the scheduler, since
* pthread_cond_signal() signals waiting threads in FIFO order.
*/
pthread_cond_broadcast(&(*sem)->gtzero);
}
if ((*sem)->nwaiters > 0)
pthread_cond_signal(&(*sem)->gtzero);
pthread_mutex_unlock(&(*sem)->lock);