本文整理汇总了C++中VLC_THREAD_ASSERT函数的典型用法代码示例。如果您正苦于以下问题:C++ VLC_THREAD_ASSERT函数的具体用法?C++ VLC_THREAD_ASSERT怎么用?C++ VLC_THREAD_ASSERT使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了VLC_THREAD_ASSERT函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: vlc_cond_timedwait
/**
* Waits for a condition variable up to a certain date.
* 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,
* then locked again when waking up.
* @param deadline <b>absolute</b> timeout
*
* @return 0 if the condition was signaled, an error code in case of timeout.
*/
int vlc_cond_timedwait (vlc_cond_t *p_condvar, vlc_mutex_t *p_mutex,
mtime_t deadline)
{
#if defined(__APPLE__) && !defined(__powerpc__) && !defined( __ppc__ ) && !defined( __ppc64__ )
/* mdate() is the monotonic clock, timedwait origin is gettimeofday() which
* isn't monotonic. Use imedwait_relative_np() instead
*/
mtime_t base = mdate();
deadline -= base;
if (deadline < 0)
deadline = 0;
lldiv_t d = lldiv( deadline, CLOCK_FREQ );
struct timespec ts = { d.quot, d.rem * (1000000000 / CLOCK_FREQ) };
int val = pthread_cond_timedwait_relative_np(p_condvar, p_mutex, &ts);
if (val != ETIMEDOUT)
VLC_THREAD_ASSERT ("timed-waiting on condition");
return val;
#else
lldiv_t d = lldiv( deadline, CLOCK_FREQ );
struct timespec ts = { d.quot, d.rem * (1000000000 / CLOCK_FREQ) };
int val = pthread_cond_timedwait (p_condvar, p_mutex, &ts);
if (val != ETIMEDOUT)
VLC_THREAD_ASSERT ("timed-waiting on condition");
return val;
#endif
}
示例2: vlc_sem_post
/**
* Increments the value of a semaphore.
*/
int vlc_sem_post (vlc_sem_t *sem)
{
int val = sem_post (sem);
if (val != EOVERFLOW)
VLC_THREAD_ASSERT ("unlocking semaphore");
return val;
}
示例3: vlc_cond_destroy
/* Destroys a condition variable. No threads shall be waiting or signaling the
* condition.
* parameter: p_condvar condition variable to destroy */
void vlc_cond_destroy (vlc_cond_t *p_condvar)
{
int val = pthread_cond_destroy( p_condvar );
/* due to a faulty pthread implementation within Darwin 11 and
* later condition variables cannot be destroyed without
* terminating the application immediately.
* This Darwin kernel issue is still present in version 13
* and might not be resolved prior to Darwin 15.
* radar://12496249
*
* To work-around this, we are just leaking the condition variable
* which is acceptable due to VLC's low number of created variables
* and its usually limited runtime.
* Ideally, we should implement a re-useable pool.
*/
if (val != 0) {
#ifndef NDEBUG
printf("pthread_cond_destroy returned %i\n", val);
#endif
if (val == EBUSY)
return;
}
VLC_THREAD_ASSERT ("destroying condition");
}
示例4: vlc_sem_wait
/**
* Atomically wait for the semaphore to become non-zero (if needed),
* then decrements it.
*/
void vlc_sem_wait (vlc_sem_t *sem)
{
int val;
do
val = sem_wait (sem);
while (val == EINTR);
VLC_THREAD_ASSERT ("locking semaphore");
}
示例5: vlc_cond_timedwait
/**
* Waits for a condition variable up to a certain date.
* 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,
* then locked again when waking up.
* @param deadline <b>absolute</b> timeout
*
* @return 0 if the condition was signaled, an error code in case of timeout.
*/
int vlc_cond_timedwait (vlc_cond_t *p_condvar, vlc_mutex_t *p_mutex,
mtime_t deadline)
{
struct timespec ts = mtime_to_ts (deadline);
int val = pthread_cond_timedwait (p_condvar, p_mutex, &ts);
if (val != ETIMEDOUT)
VLC_THREAD_ASSERT ("timed-waiting on condition");
return val;
}
示例6: vlc_join
void vlc_join (vlc_thread_t handle, void **result)
{
vlc_sem_wait (&handle->finished);
vlc_sem_destroy (&handle->finished);
int val = pthread_join (handle->thread, result);
VLC_THREAD_ASSERT ("joining thread");
clean_detached_thread(handle);
}
示例7: vlc_timer_destroy
/**
* Destroys an initialized timer. If needed, the timer is first disarmed.
* This function is undefined if the specified timer is not initialized.
*
* @warning This function <b>must</b> be called before the timer data can be
* freed and before the timer callback function can be unloaded.
*
* @param timer to destroy
*/
void vlc_timer_destroy (vlc_timer_t *id)
{
#ifdef HAVE_POSIX_TIMER
int val = timer_delete (id->handle);
VLC_THREAD_ASSERT ("deleting timer");
#else
timer_not_supported();
#endif
}
示例8: vlc_join
void vlc_join (vlc_thread_t handle, void **result)
{
vlc_sem_wait (&handle->finished);
vlc_sem_destroy (&handle->finished);
int val = pthread_join (handle->thread, result);
VLC_THREAD_ASSERT ("joining thread");
vlc_mutex_destroy(&handle->lock);
free(handle);
}
示例9: vlc_sem_wait
/* Atomically wait for the semaphore to become non-zero (if needed),
* then decrements it. */
void vlc_sem_wait (vlc_sem_t *sem)
{
int val;
if (likely(semaphore_wait(*sem) == KERN_SUCCESS))
return;
val = EINVAL;
VLC_THREAD_ASSERT ("locking semaphore");
}
示例10: vlc_sem_destroy
/* Destroy a semaphore. */
void vlc_sem_destroy (vlc_sem_t *sem)
{
int val;
if (likely(semaphore_destroy(mach_task_self(), *sem) == KERN_SUCCESS))
return;
val = EINVAL;
VLC_THREAD_ASSERT ("destroying semaphore");
}
示例11: vlc_cond_timedwait
int vlc_cond_timedwait (vlc_cond_t *condvar, vlc_mutex_t *p_mutex,
mtime_t deadline)
{
struct timespec ts = mtime_to_ts (deadline);
vlc_thread_t th = thread;
int (*cb)(pthread_cond_t *, pthread_mutex_t *, const struct timespec *);
if (th != NULL)
{
vlc_testcancel ();
if (vlc_mutex_trylock (&th->lock) == 0)
{
th->cond = &condvar->cond;
vlc_mutex_unlock (&th->lock);
}
else
{ /* The lock is already held by another thread.
* => That other thread has just cancelled this one. */
vlc_testcancel ();
/* Cancellation did not occur even though this thread is cancelled.
* => Cancellation is disabled. */
th = NULL;
}
}
switch (condvar->clock)
{
case CLOCK_REALTIME:
cb = pthread_cond_timedwait;
break;
case CLOCK_MONOTONIC:
cb = pthread_cond_timedwait_monotonic_np;
break;
default:
assert (0);
}
int val = cb (&condvar->cond, p_mutex, &ts);
if (val != ETIMEDOUT)
VLC_THREAD_ASSERT ("timed-waiting on condition");
if (th != NULL)
{
if (vlc_mutex_trylock (&th->lock) == 0)
{
thread->cond = NULL;
vlc_mutex_unlock (&th->lock);
}
/* Else: This thread was cancelled and is cancellable.
vlc_testcancel() will take of it right there: */
vlc_testcancel();
}
return val;
}
示例12: vlc_sem_wait
/**
* Atomically wait for the semaphore to become non-zero (if needed),
* then decrements it.
*/
void vlc_sem_wait (vlc_sem_t *sem)
{
int val;
do
if (likely(sem_wait (sem) == 0))
return;
while ((val = errno) == EINTR);
VLC_THREAD_ASSERT ("locking semaphore");
}
示例13: vlc_sem_destroy
/**
* Destroys a semaphore.
*/
void vlc_sem_destroy (vlc_sem_t *sem)
{
int val;
if (likely(sem_destroy (sem) == 0))
return;
val = errno;
VLC_THREAD_ASSERT ("destroying semaphore");
}
示例14: vlc_sem_post
/* Increment the value of a semaphore.
* returns 0 on success, EOVERFLOW in case of integer overflow */
int vlc_sem_post (vlc_sem_t *sem)
{
int val;
if (likely(semaphore_signal(*sem) == KERN_SUCCESS))
return 0;
val = EINVAL;
if (unlikely(val != EOVERFLOW))
VLC_THREAD_ASSERT ("unlocking semaphore");
return val;
}
示例15: vlc_sem_post
/**
* 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;
if (likely(sem_post (sem) == 0))
return 0;
val = errno;
if (unlikely(val != EOVERFLOW))
VLC_THREAD_ASSERT ("unlocking semaphore");
return val;
}