Commit 2ca95bb1 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

interrupt: add vlc_mwait_i11e() and vlc_msleep_i11e()

parent 575a1925
......@@ -62,6 +62,33 @@ struct msghdr;
*/
VLC_API int vlc_sem_wait_i11e(vlc_sem_t *);
/**
* Interruptible variant of mwait().
*
* Waits for a specified timestamp or, if the calling thread has an
* interruption context, an interruption.
*
* @return EINTR if an interruption occurred, otherwise 0 once the timestamp is
* reached.
*/
VLC_API int vlc_mwait_i11e(mtime_t);
/**
* Interruptible variant of msleep().
*
* Waits for a specified timeout duration or, if the calling thread has an
* interruption context, an interruption.
*
* @param delay timeout value (in microseconds)
*
* @return EINTR if an interruption occurred, otherwise 0 once the timeout
* expired.
*/
static inline int vlc_msleep_i11e(mtime_t delay)
{
return vlc_mwait_i11e(mdate() + delay);
}
/**
* Interruptible variant of poll().
*
......
......@@ -550,6 +550,7 @@ vlc_sendmsg_i11e
vlc_sendto_i11e
vlc_accept_i11e
vlc_sem_wait_i11e
vlc_mwait_i11e
vlc_interrupt_create
vlc_interrupt_destroy
vlc_interrupt_set
......
......@@ -258,6 +258,50 @@ int vlc_sem_wait_i11e(vlc_sem_t *sem)
return vlc_interrupt_finish(ctx);
}
static void vlc_mwait_i11e_wake(void *opaque)
{
vlc_cond_signal(opaque);
}
static void vlc_mwait_i11e_cleanup(void *opaque)
{
vlc_interrupt_t *ctx = opaque;
vlc_cond_t *cond = ctx->data;
vlc_mutex_unlock(&ctx->lock);
vlc_interrupt_finish(ctx);
vlc_cond_destroy(cond);
}
int vlc_mwait_i11e(mtime_t deadline)
{
vlc_interrupt_t *ctx = vlc_threadvar_get(vlc_interrupt_var);
if (ctx == NULL)
return mwait(deadline), 0;
vlc_cond_t wait;
vlc_cond_init(&wait);
int ret = vlc_interrupt_prepare(ctx, vlc_mwait_i11e_wake, &wait);
if (ret)
{
vlc_cond_destroy(&wait);
vlc_testcancel();
return ret;
}
vlc_mutex_lock(&ctx->lock);
vlc_cleanup_push(vlc_mwait_i11e_cleanup, ctx);
while (!ctx->interrupted
&& vlc_cond_timedwait(&wait, &ctx->lock, deadline) == 0);
vlc_cleanup_pop();
vlc_mutex_unlock(&ctx->lock);
ret = vlc_interrupt_finish(ctx);
vlc_cond_destroy(&wait);
return ret;
}
#ifndef _WIN32
static void vlc_poll_i11e_wake(void *opaque)
{
......
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