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

KO Myung-Hun git at videolan.org
Tue Dec 8 10:18:09 CET 2015


vlc/vlc-2.2 | branch: master | KO Myung-Hun <komh78 at gmail.com> | Sun Dec  6 18:57:39 2015 +0900| [827a5bf2304a23e381b5ebf2d19590840560ebf6] | 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>
(cherry picked from commit b8242eeb84ac626d58c55a66288e79da6dffdd08)
Signed-off-by: KO Myung-Hun <komh at chollian.net>
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

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

 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 7d49c1c..5d982d4 100644
--- a/src/os2/thread.c
+++ b/src/os2/thread.c
@@ -302,18 +302,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);
-        }
     }
 }
 
@@ -332,12 +320,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
@@ -348,6 +336,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