Make sem_post() safe to call from within a signal handler, as required by

POSIX/SUSv2.
This commit is contained in:
jasone 2000-08-01 21:19:09 +00:00
parent c467495440
commit 1ff9faf229
6 changed files with 30 additions and 0 deletions

View File

@ -48,6 +48,9 @@ If there are threads blocked on the semaphore when
is called, then the highest priority thread that has been blocked the longest on
the semaphore will be allowed to return from
.Fn sem_wait .
.Pp
.Fn sem_post
is signal-reentrant and may be called within signal handlers.
.Sh RETURN VALUES
If successful,
.Fn sem_post

View File

@ -48,6 +48,9 @@ If there are threads blocked on the semaphore when
is called, then the highest priority thread that has been blocked the longest on
the semaphore will be allowed to return from
.Fn sem_wait .
.Pp
.Fn sem_post
is signal-reentrant and may be called within signal handlers.
.Sh RETURN VALUES
If successful,
.Fn sem_post

View File

@ -206,6 +206,12 @@ sem_post(sem_t *sem)
_SEM_CHECK_VALIDITY(sem);
/*
* sem_post() is required to be safe to call from within signal
* handlers. Thus, we must defer signals.
*/
_thread_kern_sig_defer();
pthread_mutex_lock(&(*sem)->lock);
(*sem)->count++;
@ -221,6 +227,7 @@ sem_post(sem_t *sem)
pthread_mutex_unlock(&(*sem)->lock);
_thread_kern_sig_defer();
retval = 0;
RETURN:
return retval;

View File

@ -206,6 +206,12 @@ sem_post(sem_t *sem)
_SEM_CHECK_VALIDITY(sem);
/*
* sem_post() is required to be safe to call from within signal
* handlers. Thus, we must defer signals.
*/
_thread_kern_sig_defer();
pthread_mutex_lock(&(*sem)->lock);
(*sem)->count++;
@ -221,6 +227,7 @@ sem_post(sem_t *sem)
pthread_mutex_unlock(&(*sem)->lock);
_thread_kern_sig_defer();
retval = 0;
RETURN:
return retval;

View File

@ -48,6 +48,9 @@ If there are threads blocked on the semaphore when
is called, then the highest priority thread that has been blocked the longest on
the semaphore will be allowed to return from
.Fn sem_wait .
.Pp
.Fn sem_post
is signal-reentrant and may be called within signal handlers.
.Sh RETURN VALUES
If successful,
.Fn sem_post

View File

@ -206,6 +206,12 @@ sem_post(sem_t *sem)
_SEM_CHECK_VALIDITY(sem);
/*
* sem_post() is required to be safe to call from within signal
* handlers. Thus, we must defer signals.
*/
_thread_kern_sig_defer();
pthread_mutex_lock(&(*sem)->lock);
(*sem)->count++;
@ -221,6 +227,7 @@ sem_post(sem_t *sem)
pthread_mutex_unlock(&(*sem)->lock);
_thread_kern_sig_defer();
retval = 0;
RETURN:
return retval;