[vlc-devel] [PATCH] src: os2: fix locking at quit

KO Myung-Hun komh78 at gmail.com
Sat Oct 3 14:15:18 CEST 2015


Sometimes, especially at quit, vlc_cond_(timed)wait() may be called
very frequently. And this may exceed the limit the post count of
OS/2 event semaphore. As a result, waiting thread numbers cannot be
calculated properly.

To avoid this, increase/decrease waiting thread numbers in
vlc_cond_wait_common() instead of separating it into vlc_cond_signal()
and vlc_cond_wait_common().
---
 src/os2/thread.c | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)

diff --git a/src/os2/thread.c b/src/os2/thread.c
index fa677ad..e805d08 100644
--- a/src/os2/thread.c
+++ b/src/os2/thread.c
@@ -350,18 +350,6 @@ void vlc_cond_signal (vlc_cond_t *p_condvar)
 
         DosWaitEventSem (p_condvar->hevAck, SEM_INDEFINITE_WAIT);
         DosResetEventSem (p_condvar->hevAck, &ulPost);
-
-        while (ulPost-- > 0)
-            __atomic_decrement (&p_condvar->waiters);
-
-        /* Already timed out ? */
-        if (__atomic_cmpxchg32 (&p_condvar->waiters, 0, 0) &&
-            __atomic_cmpxchg32 (&p_condvar->signaled, 1, 1))
-        {
-            /* Clear signaled status */
-            __atomic_xchg (&p_condvar->signaled, 0);
-            DosResetEventSem (p_condvar->hev, &ulPost);
-        }
     }
 }
 
@@ -380,12 +368,12 @@ static int vlc_cond_wait_common (vlc_cond_t *p_condvar, vlc_mutex_t *p_mutex,
     ULONG ulPost;
     ULONG rc;
 
-    __atomic_increment (&p_condvar->waiters);
-
     do
     {
         vlc_testcancel();
 
+        __atomic_increment (&p_condvar->waiters);
+
         vlc_mutex_unlock (p_mutex);
 
         do
@@ -396,6 +384,8 @@ static int vlc_cond_wait_common (vlc_cond_t *p_condvar, vlc_mutex_t *p_mutex,
         } while (rc == NO_ERROR &&
                  __atomic_cmpxchg32 (&p_condvar->signaled, 0, 1) == 0);
 
+        __atomic_decrement (&p_condvar->waiters);
+
         DosPostEventSem (p_condvar->hevAck);
 
         vlc_mutex_lock (p_mutex);
-- 
2.5.2



More information about the vlc-devel mailing list