[vlc-devel] commit: pthread: fix semaphore error handling ( Rémi Denis-Courmont )
git version control
git at videolan.org
Sun Jan 17 11:14:54 CET 2010
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Jan 17 12:13:31 2010 +0200| [73c88a2e7096b7f9a2ad0af83081bd2c19032945] | committer: 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).
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=73c88a2e7096b7f9a2ad0af83081bd2c19032945
---
src/misc/pthread.c | 20 +++++++++++++++-----
1 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/src/misc/pthread.c b/src/misc/pthread.c
index 2a25b61..ee874da 100644
--- a/src/misc/pthread.c
+++ b/src/misc/pthread.c
@@ -396,17 +396,24 @@ void vlc_sem_init (vlc_sem_t *sem, unsigned value)
*/
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");
}
/**
* 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 val = sem_post (sem);
- if (val != EOVERFLOW)
+ if (likely(sem_post (sem) == 0))
+ return 0;
+
+ int val = errno;
+ if (unlikely(val != EOVERFLOW))
VLC_THREAD_ASSERT ("unlocking semaphore");
return val;
}
@@ -418,9 +425,12 @@ int vlc_sem_post (vlc_sem_t *sem)
void vlc_sem_wait (vlc_sem_t *sem)
{
int val;
+
do
- val = sem_wait (sem);
- while (val == EINTR);
+ if (likely(sem_wait (sem) == 0))
+ return;
+ while ((val = errno) == EINTR);
+
VLC_THREAD_ASSERT ("locking semaphore");
}
More information about the vlc-devel
mailing list