diff options
| -rw-r--r-- | lib/libc_r/man/sem_post.3 | 3 | ||||
| -rw-r--r-- | lib/libc_r/uthread/uthread_sem.c | 7 |
2 files changed, 10 insertions, 0 deletions
diff --git a/lib/libc_r/man/sem_post.3 b/lib/libc_r/man/sem_post.3 index 906d86d87c2b..34fef83c614d 100644 --- a/lib/libc_r/man/sem_post.3 +++ b/lib/libc_r/man/sem_post.3 @@ -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 diff --git a/lib/libc_r/uthread/uthread_sem.c b/lib/libc_r/uthread/uthread_sem.c index 10dec5ed036f..2dcf72223fc3 100644 --- a/lib/libc_r/uthread/uthread_sem.c +++ b/lib/libc_r/uthread/uthread_sem.c @@ -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_undefer(); retval = 0; RETURN: return retval; |
