Commit 4a9086ff authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

interrupt: add internal vlc_interrupt_get() helper

parent b257a2cf
...@@ -150,6 +150,11 @@ vlc_interrupt_t *vlc_interrupt_set(vlc_interrupt_t *newctx) ...@@ -150,6 +150,11 @@ vlc_interrupt_t *vlc_interrupt_set(vlc_interrupt_t *newctx)
return oldctx; return oldctx;
} }
static vlc_interrupt_t *vlc_interrupt_get(void)
{
return vlc_threadvar_get(vlc_interrupt_var);
}
/** /**
* Prepares to enter interruptible wait. * Prepares to enter interruptible wait.
* @param cb callback to interrupt the wait (i.e. wake up the thread) * @param cb callback to interrupt the wait (i.e. wake up the thread)
...@@ -161,7 +166,7 @@ static void vlc_interrupt_prepare(vlc_interrupt_t *ctx, ...@@ -161,7 +166,7 @@ static void vlc_interrupt_prepare(vlc_interrupt_t *ctx,
void (*cb)(void *), void *data) void (*cb)(void *), void *data)
{ {
assert(ctx != NULL); assert(ctx != NULL);
assert(ctx == vlc_threadvar_get(vlc_interrupt_var)); assert(ctx == vlc_interrupt_get());
vlc_mutex_lock(&ctx->lock); vlc_mutex_lock(&ctx->lock);
assert(ctx->callback == NULL); assert(ctx->callback == NULL);
...@@ -189,7 +194,7 @@ static int vlc_interrupt_finish(vlc_interrupt_t *ctx) ...@@ -189,7 +194,7 @@ static int vlc_interrupt_finish(vlc_interrupt_t *ctx)
int ret = 0; int ret = 0;
assert(ctx != NULL); assert(ctx != NULL);
assert(ctx == vlc_threadvar_get(vlc_interrupt_var)); assert(ctx == vlc_interrupt_get());
/* Wait for pending callbacks to prevent access by other threads. */ /* Wait for pending callbacks to prevent access by other threads. */
vlc_mutex_lock(&ctx->lock); vlc_mutex_lock(&ctx->lock);
...@@ -205,14 +210,14 @@ static int vlc_interrupt_finish(vlc_interrupt_t *ctx) ...@@ -205,14 +210,14 @@ static int vlc_interrupt_finish(vlc_interrupt_t *ctx)
void vlc_interrupt_register(void (*cb)(void *), void *opaque) void vlc_interrupt_register(void (*cb)(void *), void *opaque)
{ {
vlc_interrupt_t *ctx = vlc_threadvar_get(vlc_interrupt_var); vlc_interrupt_t *ctx = vlc_interrupt_get();
if (ctx != NULL) if (ctx != NULL)
vlc_interrupt_prepare(ctx, cb, opaque); vlc_interrupt_prepare(ctx, cb, opaque);
} }
int vlc_interrupt_unregister(void) int vlc_interrupt_unregister(void)
{ {
vlc_interrupt_t *ctx = vlc_threadvar_get(vlc_interrupt_var); vlc_interrupt_t *ctx = vlc_interrupt_get();
return (ctx != NULL) ? vlc_interrupt_finish(ctx) : 0; return (ctx != NULL) ? vlc_interrupt_finish(ctx) : 0;
} }
...@@ -231,7 +236,7 @@ void vlc_interrupt_kill(vlc_interrupt_t *ctx) ...@@ -231,7 +236,7 @@ void vlc_interrupt_kill(vlc_interrupt_t *ctx)
bool vlc_killed(void) bool vlc_killed(void)
{ {
vlc_interrupt_t *ctx = vlc_threadvar_get(vlc_interrupt_var); vlc_interrupt_t *ctx = vlc_interrupt_get();
return (ctx != NULL) && atomic_load(&ctx->killed); return (ctx != NULL) && atomic_load(&ctx->killed);
} }
...@@ -243,7 +248,7 @@ static void vlc_interrupt_sem(void *opaque) ...@@ -243,7 +248,7 @@ static void vlc_interrupt_sem(void *opaque)
int vlc_sem_wait_i11e(vlc_sem_t *sem) int vlc_sem_wait_i11e(vlc_sem_t *sem)
{ {
vlc_interrupt_t *ctx = vlc_threadvar_get(vlc_interrupt_var); vlc_interrupt_t *ctx = vlc_interrupt_get();
if (ctx == NULL) if (ctx == NULL)
return vlc_sem_wait(sem), 0; return vlc_sem_wait(sem), 0;
...@@ -273,7 +278,7 @@ static void vlc_mwait_i11e_cleanup(void *opaque) ...@@ -273,7 +278,7 @@ static void vlc_mwait_i11e_cleanup(void *opaque)
int vlc_mwait_i11e(mtime_t deadline) int vlc_mwait_i11e(mtime_t deadline)
{ {
vlc_interrupt_t *ctx = vlc_threadvar_get(vlc_interrupt_var); vlc_interrupt_t *ctx = vlc_interrupt_get();
if (ctx == NULL) if (ctx == NULL)
return mwait(deadline), 0; return mwait(deadline), 0;
...@@ -308,7 +313,7 @@ void vlc_interrupt_forward_start(vlc_interrupt_t *to, void *data[2]) ...@@ -308,7 +313,7 @@ void vlc_interrupt_forward_start(vlc_interrupt_t *to, void *data[2])
{ {
data[0] = data[1] = NULL; data[0] = data[1] = NULL;
vlc_interrupt_t *from = vlc_threadvar_get(vlc_interrupt_var); vlc_interrupt_t *from = vlc_interrupt_get();
if (from == NULL) if (from == NULL)
return; return;
...@@ -417,7 +422,7 @@ static int vlc_poll_i11e_inner(struct pollfd *restrict fds, unsigned nfds, ...@@ -417,7 +422,7 @@ static int vlc_poll_i11e_inner(struct pollfd *restrict fds, unsigned nfds,
int vlc_poll_i11e(struct pollfd *fds, unsigned nfds, int timeout) int vlc_poll_i11e(struct pollfd *fds, unsigned nfds, int timeout)
{ {
vlc_interrupt_t *ctx = vlc_threadvar_get(vlc_interrupt_var); vlc_interrupt_t *ctx = vlc_interrupt_get();
if (ctx == NULL) if (ctx == NULL)
return poll(fds, nfds, timeout); return poll(fds, nfds, timeout);
...@@ -614,7 +619,7 @@ static void vlc_poll_i11e_cleanup(void *opaque) ...@@ -614,7 +619,7 @@ static void vlc_poll_i11e_cleanup(void *opaque)
int vlc_poll_i11e(struct pollfd *fds, unsigned nfds, int timeout) int vlc_poll_i11e(struct pollfd *fds, unsigned nfds, int timeout)
{ {
vlc_interrupt_t *ctx = vlc_threadvar_get(vlc_interrupt_var); vlc_interrupt_t *ctx = vlc_interrupt_get();
if (ctx == NULL) if (ctx == NULL)
return vlc_poll(fds, nfds, timeout); return vlc_poll(fds, nfds, timeout);
......
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