[vlc-commits] src: os2: fix locking at quit

KO Myung-Hun git at videolan.org
Tue Oct 6 12:22:11 CEST 2015


vlc | branch: master | KO Myung-Hun <komh78 at gmail.com> | Sat Oct  3 21:15:18 2015 +0900| [b8242eeb84ac626d58c55a66288e79da6dffdd08] | committer: Jean-Baptiste Kempf

src: os2: fix locking at quit

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().

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

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

 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 e221632..6407a08 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);



More information about the vlc-commits mailing list