[vlc-commits] interrupt: add replacement for vlc_object_alive()

Rémi Denis-Courmont git at videolan.org
Wed Jul 1 18:22:14 CEST 2015


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue Jun 30 23:52:51 2015 +0300| [ebb675dee6db85f46b273620c5fabdb904a02cc0] | committer: Rémi Denis-Courmont

interrupt: add replacement for vlc_object_alive()

There are still many cases where waking up the thread sleeping is only
half of the problem and waking it up half of the solution. For instance,
the net_* and stream_* I/O functions have no ways to return a non-fatal
error.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=ebb675dee6db85f46b273620c5fabdb904a02cc0
---

 include/vlc_interrupt.h |   11 +++++++++++
 src/input/input.c       |    4 +---
 src/libvlccore.sym      |    2 ++
 src/misc/interrupt.c    |   16 ++++++++++++++++
 src/misc/interrupt.h    |    2 ++
 5 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/include/vlc_interrupt.h b/include/vlc_interrupt.h
index 7cc528b..6e52f4d 100644
--- a/include/vlc_interrupt.h
+++ b/include/vlc_interrupt.h
@@ -142,5 +142,16 @@ VLC_API vlc_interrupt_t *vlc_interrupt_set(vlc_interrupt_t *);
  */
 VLC_API void vlc_interrupt_raise(vlc_interrupt_t *);
 
+/**
+ * Marks the interruption context as "killed". This is not reversible.
+ */
+VLC_API void vlc_interrupt_kill(vlc_interrupt_t *);
+
+/**
+ * Indicates whether the interruption context of the calling thread (if any)
+ * was killed with vlc_interrupt_kill().
+ */
+VLC_API bool vlc_killed(void) VLC_USED;
+
 /** @} @} */
 #endif
diff --git a/src/input/input.c b/src/input/input.c
index 3e021a8..fff1082 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -236,9 +236,7 @@ void input_Stop( input_thread_t *p_input )
     sys->is_stopped = true;
     vlc_cond_signal( &sys->wait_control );
     vlc_mutex_unlock( &sys->lock_control );
-    /* Interrupt access/stream/demux/etc *after* the input is stopped.
-     * Otherwise the interruption could be mistreated as a spurious wake-up. */
-    vlc_interrupt_raise( &sys->interrupt );
+    vlc_interrupt_kill( &sys->interrupt );
 }
 
 /**
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 18805a2..3c24b79 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -554,6 +554,8 @@ vlc_interrupt_create
 vlc_interrupt_destroy
 vlc_interrupt_set
 vlc_interrupt_raise
+vlc_interrupt_kill
+vlc_killed
 vlc_join
 vlc_list_children
 vlc_list_release
diff --git a/src/misc/interrupt.c b/src/misc/interrupt.c
index 0b84f1b..7ec7fa9 100644
--- a/src/misc/interrupt.c
+++ b/src/misc/interrupt.c
@@ -74,6 +74,7 @@ void vlc_interrupt_init(vlc_interrupt_t *ctx)
 
     vlc_mutex_init(&ctx->lock);
     ctx->interrupted = false;
+    atomic_init(&ctx->killed, false);
 #ifndef NDEBUG
     ctx->attached = false;
 #endif
@@ -217,6 +218,21 @@ static void vlc_interrupt_cleanup(void *opaque)
     vlc_interrupt_finish(opaque);
 }
 
+void vlc_interrupt_kill(vlc_interrupt_t *ctx)
+{
+    assert(ctx != NULL);
+
+    atomic_store(&ctx->killed, true);
+    vlc_interrupt_raise(ctx);
+}
+
+bool vlc_killed(void)
+{
+    vlc_interrupt_t *ctx = vlc_threadvar_get(vlc_interrupt_var);
+
+    return (ctx != NULL) && atomic_load(&ctx->killed);
+}
+
 static void vlc_interrupt_sem(void *opaque)
 {
     vlc_sem_post(opaque);
diff --git a/src/misc/interrupt.h b/src/misc/interrupt.h
index 061158a..47d57e5 100644
--- a/src/misc/interrupt.h
+++ b/src/misc/interrupt.h
@@ -23,6 +23,7 @@
 # define LIBVLC_INPUT_SIGNAL_H 1
 
 # include <vlc_interrupt.h>
+# include <vlc_atomic.h>
 
 void vlc_interrupt_init(vlc_interrupt_t *);
 void vlc_interrupt_deinit(vlc_interrupt_t *);
@@ -34,6 +35,7 @@ struct vlc_interrupt
 #ifndef NDEBUG
     bool attached;
 #endif
+    atomic_bool killed;
     void (*callback)(void *);
     void *data;
 };



More information about the vlc-commits mailing list