VLC_THREAD_ASSERT ("unlocking mutex");
}
-/*****************************************************************************
- * vlc_cond_init: initialize a condition variable
- *****************************************************************************/
-void vlc_cond_init( vlc_cond_t *p_condvar )
+/**
+ * Initializes a condition variable.
+ */
+void vlc_cond_init (vlc_cond_t *p_condvar)
{
pthread_condattr_t attr;
pthread_condattr_destroy (&attr);
}
+/**
+ * Initializes a condition variable.
+ * Contrary to vlc_cond_init(), the wall clock will be used as a reference for
+ * the vlc_cond_timedwait() time-out parameter.
+ */
+void vlc_cond_init_daytime (vlc_cond_t *p_condvar)
+{
+ if (unlikely(pthread_cond_init (p_condvar, NULL)))
+ abort ();
+}
+
/**
* Destroys a condition variable. No threads shall be waiting or signaling the
* condition.
/**
* Waits for a condition variable up to a certain date.
- * This works like vlc_cond_wait(), except for the additional timeout.
+ * This works like vlc_cond_wait(), except for the additional time-out.
+ *
+ * If the variable was initialized with vlc_cond_init(), the timeout has the
+ * same arbitrary origin as mdate(). If the variable was initialized with
+ * vlc_cond_init_daytime(), the timeout is expressed from the Unix epoch.
*
* @param p_condvar condition variable to wait on
* @param p_mutex mutex which is unlocked while waiting,
*/
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;
}
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");
}
if (!initialized)
{
#ifndef __APPLE__
- if (config_GetInt (p_libvlc, "rt-priority"))
+ if (var_InheritBool (p_libvlc, "rt-priority"))
#endif
{
- rt_offset = config_GetInt (p_libvlc, "rt-offset");
+ rt_offset = var_InheritInteger (p_libvlc, "rt-offset");
rt_priorities = true;
}
initialized = true;