[vlc-devel] [PATCH 2/4] src: os2: fix locking at quit
KO Myung-Hun
komh78 at gmail.com
Sun Dec 6 10:57:39 CET 2015
From: KO Myung-Hun <komh78 at gmail.com>
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>
---
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);
--
2.6.0
More information about the vlc-devel
mailing list