Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
GSoC
GSoC2018
macOS
vlc
Commits
fffde849
Commit
fffde849
authored
Jun 15, 2017
by
Rémi Denis-Courmont
Browse files
interrupt: simplify using thread_local
parent
4e05fc60
Changes
1
Show whitespace changes
Inline
Side-by-side
src/misc/interrupt.c
View file @
fffde849
...
@@ -43,21 +43,13 @@
...
@@ -43,21 +43,13 @@
#include "interrupt.h"
#include "interrupt.h"
#include "libvlc.h"
#include "libvlc.h"
static
unsigned
vlc_interrupt_refs
=
0
;
static
thread_local
vlc_interrupt_t
*
vlc_interrupt_var
;
static
vlc_rwlock_t
vlc_interrupt_lock
=
VLC_STATIC_RWLOCK
;
static
vlc_threadvar_t
vlc_interrupt_var
;
/**
/**
* Initializes an interruption context.
* Initializes an interruption context.
*/
*/
void
vlc_interrupt_init
(
vlc_interrupt_t
*
ctx
)
void
vlc_interrupt_init
(
vlc_interrupt_t
*
ctx
)
{
{
vlc_rwlock_wrlock
(
&
vlc_interrupt_lock
);
assert
(
vlc_interrupt_refs
<
UINT_MAX
);
if
(
vlc_interrupt_refs
++
==
0
)
vlc_threadvar_create
(
&
vlc_interrupt_var
,
NULL
);
vlc_rwlock_unlock
(
&
vlc_interrupt_lock
);
vlc_mutex_init
(
&
ctx
->
lock
);
vlc_mutex_init
(
&
ctx
->
lock
);
ctx
->
interrupted
=
false
;
ctx
->
interrupted
=
false
;
atomic_init
(
&
ctx
->
killed
,
false
);
atomic_init
(
&
ctx
->
killed
,
false
);
...
@@ -80,12 +72,6 @@ void vlc_interrupt_deinit(vlc_interrupt_t *ctx)
...
@@ -80,12 +72,6 @@ void vlc_interrupt_deinit(vlc_interrupt_t *ctx)
{
{
assert
(
ctx
->
callback
==
NULL
);
assert
(
ctx
->
callback
==
NULL
);
vlc_mutex_destroy
(
&
ctx
->
lock
);
vlc_mutex_destroy
(
&
ctx
->
lock
);
vlc_rwlock_wrlock
(
&
vlc_interrupt_lock
);
assert
(
vlc_interrupt_refs
>
0
);
if
(
--
vlc_interrupt_refs
==
0
)
vlc_threadvar_delete
(
&
vlc_interrupt_var
);
vlc_rwlock_unlock
(
&
vlc_interrupt_lock
);
}
}
void
vlc_interrupt_destroy
(
vlc_interrupt_t
*
ctx
)
void
vlc_interrupt_destroy
(
vlc_interrupt_t
*
ctx
)
...
@@ -112,29 +98,15 @@ void vlc_interrupt_raise(vlc_interrupt_t *ctx)
...
@@ -112,29 +98,15 @@ void vlc_interrupt_raise(vlc_interrupt_t *ctx)
vlc_interrupt_t
*
vlc_interrupt_set
(
vlc_interrupt_t
*
newctx
)
vlc_interrupt_t
*
vlc_interrupt_set
(
vlc_interrupt_t
*
newctx
)
{
{
vlc_interrupt_t
*
oldctx
;
vlc_interrupt_t
*
oldctx
=
vlc_interrupt_var
;
/* This function is called to push or pop an interrupt context. Either way
* either newctx or oldctx (or both) are non-NULL. Thus vlc_interrupt_refs
* must be larger than zero and vlc_interrupt_var must be valid. And so the
* read/write lock is not needed. */
assert
(
vlc_interrupt_refs
>
0
);
oldctx
=
vlc_threadvar_get
(
vlc_interrupt_var
);
vlc_threadvar_set
(
vlc_interrupt_var
,
newctx
);
vlc_interrupt_var
=
newctx
;
return
oldctx
;
return
oldctx
;
}
}
static
vlc_interrupt_t
*
vlc_interrupt_get
(
void
)
static
vlc_interrupt_t
*
vlc_interrupt_get
(
void
)
{
{
vlc_interrupt_t
*
ctx
=
NULL
;
return
vlc_interrupt_var
;
vlc_rwlock_rdlock
(
&
vlc_interrupt_lock
);
if
(
vlc_interrupt_refs
>
0
)
ctx
=
vlc_threadvar_get
(
vlc_interrupt_var
);
vlc_rwlock_unlock
(
&
vlc_interrupt_lock
);
return
ctx
;
}
}
/**
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment