[vlc-devel] [PATCH 1/3] caca: do not rely on vlc_cancel()
RĂ©mi Denis-Courmont
remi at remlab.net
Sat Apr 11 21:12:39 CEST 2020
---
modules/video_output/caca.c | 27 +++++++++++++++++++--------
1 file changed, 19 insertions(+), 8 deletions(-)
diff --git a/modules/video_output/caca.c b/modules/video_output/caca.c
index f95d985034..de5d130803 100644
--- a/modules/video_output/caca.c
+++ b/modules/video_output/caca.c
@@ -29,7 +29,7 @@
# include "config.h"
#endif
-#include <stdnoreturn.h>
+#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <vlc_common.h>
@@ -51,6 +51,7 @@ struct vout_display_sys_t {
caca_display_t *dp;
cucul_dither_t *dither;
+ bool dead;
block_fifo_t *fifo;
vlc_thread_t thread;
vout_window_t *window;
@@ -60,23 +61,29 @@ struct vout_display_sys_t {
vlc_tick_t cursor_deadline;
};
-noreturn static void *VoutDisplayEventKeyDispatch(void *data)
+static void *VoutDisplayEventKeyDispatch(void *data)
{
vout_display_t *vd = data;
vout_display_sys_t *sys = vd->sys;
block_fifo_t *fifo = sys->fifo;
+ block_t *event;
- for (;;) {
- block_t *event = block_FifoGet(fifo);
+ do {
+ vlc_fifo_Lock(fifo);
+ while (vlc_fifo_IsEmpty(fifo) && !sys->dead)
+ vlc_fifo_Wait(fifo);
+
+ event = vlc_fifo_DequeueUnlocked(fifo);
+ vlc_fifo_Unlock(fifo);
- int cancel = vlc_savecancel();
int key;
memcpy(&key, event->p_buffer, sizeof (key));
block_Release(event);
vout_window_ReportKeyPress(sys->window, key);
- vlc_restorecancel(cancel);
- }
+ } while (event != NULL);
+
+ return NULL;
}
static void VoutDisplayEventKey(vout_display_sys_t *sys, int key)
@@ -357,7 +364,10 @@ static void Close(vout_display_t *vd)
vout_display_sys_t *sys = vd->sys;
if (sys->fifo != NULL) {
- vlc_cancel(sys->thread);
+ vlc_fifo_Lock(sys->fifo);
+ sys->dead = true;
+ vlc_fifo_Signal(sys->fifo);
+ vlc_fifo_Unlock(sys->fifo);
vlc_join(sys->thread, NULL);
block_FifoRelease(sys->fifo);
}
@@ -472,6 +482,7 @@ static int Open(vout_display_t *vd, const vout_display_cfg_t *cfg,
block_fifo_t *fifo = block_FifoNew();
if (likely(fifo != NULL)) {
+ sys->dead = false;
sys->fifo = fifo;
if (vlc_clone(&sys->thread, VoutDisplayEventKeyDispatch, vd,
--
2.26.0
More information about the vlc-devel
mailing list