[vlc-commits] win32/inhibit: simplify, avoid cancellation

Rémi Denis-Courmont git at videolan.org
Mon Apr 13 18:51:12 CEST 2020


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Apr 12 16:09:24 2020 +0300| [0fbb2d8ff465aa1528bb040f0088f78c140a43a3] | committer: Rémi Denis-Courmont

win32/inhibit: simplify, avoid cancellation

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

 modules/video_output/win32/inhibit.c | 43 ++++++++++++++----------------------
 1 file changed, 17 insertions(+), 26 deletions(-)

diff --git a/modules/video_output/win32/inhibit.c b/modules/video_output/win32/inhibit.c
index 8bd7604e30..3dac8113dd 100644
--- a/modules/video_output/win32/inhibit.c
+++ b/modules/video_output/win32/inhibit.c
@@ -35,6 +35,7 @@ struct vlc_inhibit_sys
     vlc_cond_t cond;
     vlc_thread_t thread;
     unsigned int mask;
+    bool exit;
 };
 
 static void Inhibit (vlc_inhibit_t *ih, unsigned mask)
@@ -46,47 +47,36 @@ static void Inhibit (vlc_inhibit_t *ih, unsigned mask)
     vlc_mutex_unlock(&sys->mutex);
 }
 
-static void RestoreStateOnCancel( void* p_opaque )
-{
-    VLC_UNUSED(p_opaque);
-    SetThreadExecutionState( ES_CONTINUOUS );
-}
-
 static void* Run(void* obj)
 {
     vlc_inhibit_t *ih = (vlc_inhibit_t*)obj;
     vlc_inhibit_sys_t *sys = ih->p_sys;
-    EXECUTION_STATE prev_state = ES_CONTINUOUS;
 
-    for  (unsigned int mask = 0;;)
+    vlc_mutex_lock(&sys->mutex);
+    while (!sys->exit)
     {
-        vlc_mutex_lock(&sys->mutex);
-        mutex_cleanup_push(&sys->mutex);
-        vlc_cleanup_push(RestoreStateOnCancel, ih);
-        while (mask == sys->mask)
-            vlc_cond_wait(&sys->cond, &sys->mutex);
-        mask = sys->mask;
-        vlc_mutex_unlock(&sys->mutex);
-        vlc_cleanup_pop();
-        vlc_cleanup_pop();
+        EXECUTION_STATE state = ES_CONTINUOUS;
 
-        bool suspend = (mask & VLC_INHIBIT_DISPLAY) != 0;
-        if (suspend)
+        if (sys->mask & VLC_INHIBIT_DISPLAY)
             /* Prevent monitor from powering off */
-            prev_state = SetThreadExecutionState( ES_DISPLAY_REQUIRED |
-                                                  ES_SYSTEM_REQUIRED |
-                                                  ES_CONTINUOUS );
-        else
-            SetThreadExecutionState( prev_state );
+            state |= ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED;
+
+        SetThreadExecutionState(state);
+        vlc_cond_wait(&sys->cond, &sys->mutex);
     }
-    vlc_assert_unreachable();
+    vlc_mutex_unlock(&sys->mutex);
+    SetThreadExecutionState(ES_CONTINUOUS);
+    return NULL;
 }
 
 static void CloseInhibit (vlc_object_t *obj)
 {
     vlc_inhibit_t *ih = (vlc_inhibit_t*)obj;
     vlc_inhibit_sys_t* sys = ih->p_sys;
-    vlc_cancel(sys->thread);
+    vlc_mutex_lock(&sys->mutex);
+    sys->exit = true;
+    vlc_cond_signal(&sys->cond);
+    vlc_mutex_unlock(&sys->mutex);
     vlc_join(sys->thread, NULL);
 }
 
@@ -101,6 +91,7 @@ static int OpenInhibit (vlc_object_t *obj)
     vlc_mutex_init(&sys->mutex);
     vlc_cond_init(&sys->cond);
     sys->mask = 0;
+    sys->exit = false;
 
     /* SetThreadExecutionState always needs to be called from the same thread */
     if (vlc_clone(&sys->thread, Run, ih, VLC_THREAD_PRIORITY_LOW))



More information about the vlc-commits mailing list