[vlc-devel] [PATCH] os2: thread: determine cancelable state with killable variable

KO Myung-Hun komh78 at gmail.com
Wed Dec 2 01:41:47 CET 2015


If thread cancel is disabled and cancel is requested, it causes a tight
infinite loop eating up CPU in cancellation points such as vlc_join(),
vlc_cond_wait() and vlc_cond_timedwait().
---
 src/os2/thread.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/os2/thread.c b/src/os2/thread.c
index dbb8829..357beb2 100644
--- a/src/os2/thread.c
+++ b/src/os2/thread.c
@@ -69,7 +69,7 @@ struct vlc_thread
 
 static void vlc_cancel_self (PVOID dummy);
 
-static ULONG vlc_DosWaitEventSemEx( HEV hev, ULONG ulTimeout, BOOL fCancelable )
+static ULONG vlc_DosWaitEventSemEx( HEV hev, ULONG ulTimeout )
 {
     HMUX      hmux;
     SEMRECORD asr[ 2 ];
@@ -78,10 +78,11 @@ static ULONG vlc_DosWaitEventSemEx( HEV hev, ULONG ulTimeout, BOOL fCancelable )
     ULONG     rc;
 
     struct vlc_thread *th = vlc_threadvar_get( thread_key );
-    if( th == NULL || !fCancelable )
+    if( th == NULL || !th->killable )
     {
         /* Main thread - cannot be cancelled anyway
          * Alien thread - out of our control
+         * Cancel disabled thread - ignore cancel
          */
         if( hev != NULLHANDLE )
             return DosWaitEventSem( hev, ulTimeout );
@@ -117,12 +118,12 @@ static ULONG vlc_DosWaitEventSemEx( HEV hev, ULONG ulTimeout, BOOL fCancelable )
 
 static ULONG vlc_WaitForSingleObject (HEV hev, ULONG ulTimeout)
 {
-    return vlc_DosWaitEventSemEx( hev, ulTimeout, TRUE );
+    return vlc_DosWaitEventSemEx( hev, ulTimeout );
 }
 
 static ULONG vlc_Sleep (ULONG ulTimeout)
 {
-    ULONG rc = vlc_DosWaitEventSemEx( NULLHANDLE, ulTimeout, TRUE );
+    ULONG rc = vlc_DosWaitEventSemEx( NULLHANDLE, ulTimeout );
 
     return ( rc != ERROR_TIMEOUT ) ? rc : 0;
 }
-- 
2.6.0



More information about the vlc-devel mailing list