[vlc-commits] ncurses: simplify using atomic instead of vlc_cancel()

Rémi Denis-Courmont git at videolan.org
Sun Feb 9 17:26:47 CET 2020


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Feb  9 18:12:57 2020 +0200| [e40907eaa4a35dcc64246667c18f2713a2998a4c] | committer: Rémi Denis-Courmont

ncurses: simplify using atomic instead of vlc_cancel()

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

 modules/gui/ncurses.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/modules/gui/ncurses.c b/modules/gui/ncurses.c
index f514af508c..8e3156050b 100644
--- a/modules/gui/ncurses.c
+++ b/modules/gui/ncurses.c
@@ -36,6 +36,7 @@
 #define _XOPEN_SOURCE_EXTENDED 1
 
 #include <assert.h>
+#include <stdatomic.h>
 #include <wchar.h>
 #include <sys/stat.h>
 #include <math.h>
@@ -176,6 +177,7 @@ typedef struct VLC_VECTOR(char const *) pl_item_names;
 struct intf_sys_t
 {
     vlc_thread_t    thread;
+    atomic_bool     alive;
 
     bool            color;
 
@@ -1647,17 +1649,13 @@ static const struct vlc_logger_operations log_ops = { MsgCallback, NULL };
 static void *Run(void *data)
 {
     intf_thread_t *intf = data;
+    intf_sys_t *sys = intf->p_sys;
 
-    for (;;) {
-        vlc_testcancel();
-
-        int canc = vlc_savecancel();
-
+    while (atomic_load_explicit(&sys->alive, memory_order_relaxed)) {
         Redraw(intf);
         HandleKey(intf);
-        vlc_restorecancel(canc);
     }
-    vlc_assert_unreachable();
+    return NULL;
 }
 
 /*****************************************************************************
@@ -1671,6 +1669,7 @@ static int Open(vlc_object_t *p_this)
     if (!sys)
         return VLC_ENOMEM;
 
+    atomic_init(&sys->alive, true);
     vlc_mutex_init(&sys->msg_lock);
 
     sys->verbosity = var_InheritInteger(intf, "verbose");
@@ -1738,7 +1737,7 @@ static void Close(vlc_object_t *p_this)
     intf_thread_t *intf = (intf_thread_t *)p_this;
     intf_sys_t *sys = intf->p_sys;
 
-    vlc_cancel(sys->thread);
+    atomic_store_explicit(&sys->alive, false, memory_order_relaxed);
     vlc_join(sys->thread, NULL);
 
     vlc_playlist_t *playlist = sys->playlist;



More information about the vlc-commits mailing list