Commit 73c88a2e authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

pthread: fix semaphore error handling

POSIX sem_*() functions return -1 on error and the error code in errno
(contrary to most POSIX thread functions).
parent 30c48e10
...@@ -396,17 +396,24 @@ void vlc_sem_init (vlc_sem_t *sem, unsigned value) ...@@ -396,17 +396,24 @@ void vlc_sem_init (vlc_sem_t *sem, unsigned value)
*/ */
void vlc_sem_destroy (vlc_sem_t *sem) void vlc_sem_destroy (vlc_sem_t *sem)
{ {
int val = sem_destroy (sem); if (likely(sem_destroy (sem) == 0))
return;
int val = errno;
VLC_THREAD_ASSERT ("destroying semaphore"); VLC_THREAD_ASSERT ("destroying semaphore");
} }
/** /**
* Increments the value of a semaphore. * Increments the value of a semaphore.
* @return 0 on success, EOVERFLOW in case of integer overflow
*/ */
int vlc_sem_post (vlc_sem_t *sem) int vlc_sem_post (vlc_sem_t *sem)
{ {
int val = sem_post (sem); if (likely(sem_post (sem) == 0))
if (val != EOVERFLOW) return 0;
int val = errno;
if (unlikely(val != EOVERFLOW))
VLC_THREAD_ASSERT ("unlocking semaphore"); VLC_THREAD_ASSERT ("unlocking semaphore");
return val; return val;
} }
...@@ -418,9 +425,12 @@ int vlc_sem_post (vlc_sem_t *sem) ...@@ -418,9 +425,12 @@ int vlc_sem_post (vlc_sem_t *sem)
void vlc_sem_wait (vlc_sem_t *sem) void vlc_sem_wait (vlc_sem_t *sem)
{ {
int val; int val;
do do
val = sem_wait (sem); if (likely(sem_wait (sem) == 0))
while (val == EINTR); return;
while ((val = errno) == EINTR);
VLC_THREAD_ASSERT ("locking semaphore"); VLC_THREAD_ASSERT ("locking semaphore");
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment