[vlc-commits] win32: factor common code in vlc_cond_(timed)wait()
Rémi Denis-Courmont
git at videolan.org
Mon May 18 18:29:15 CEST 2015
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon May 18 19:14:09 2015 +0300| [d1bc9375a1780964f5dff7d9437d122d8effa323] | committer: Rémi Denis-Courmont
win32: factor common code in vlc_cond_(timed)wait()
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=d1bc9375a1780964f5dff7d9437d122d8effa323
---
src/win32/thread.c | 36 +++++++++++++-----------------------
1 file changed, 13 insertions(+), 23 deletions(-)
diff --git a/src/win32/thread.c b/src/win32/thread.c
index 302e9a2..8e0319e 100644
--- a/src/win32/thread.c
+++ b/src/win32/thread.c
@@ -259,7 +259,8 @@ void vlc_cond_broadcast(vlc_cond_t *wait)
ReleaseSemaphore(wait->semaphore, waiters, NULL);
}
-void vlc_cond_wait(vlc_cond_t *wait, vlc_mutex_t *lock)
+static DWORD vlc_cond_wait_delay(vlc_cond_t *wait, vlc_mutex_t *lock,
+ DWORD delay)
{
DWORD result;
@@ -268,26 +269,29 @@ void vlc_cond_wait(vlc_cond_t *wait, vlc_mutex_t *lock)
if (wait->semaphore == NULL)
{ /* FIXME FIXME FIXME */
vlc_mutex_unlock(lock);
- result = SleepEx(50, TRUE);
+ result = SleepEx((delay > 50u) ? 50u : delay, TRUE);
}
else
{
InterlockedIncrement(&wait->waiters);
vlc_mutex_unlock(lock);
- result = vlc_WaitForSingleObject(wait->semaphore, INFINITE);
+ result = vlc_WaitForSingleObject(wait->semaphore, delay);
}
vlc_mutex_lock(lock);
if (result == WAIT_IO_COMPLETION)
vlc_testcancel();
+ return result;
+}
+
+void vlc_cond_wait(vlc_cond_t *wait, vlc_mutex_t *lock)
+{
+ vlc_cond_wait_delay(wait, lock, INFINITE);
}
int vlc_cond_timedwait(vlc_cond_t *wait, vlc_mutex_t *lock, mtime_t deadline)
{
mtime_t total;
- DWORD result;
-
- vlc_testcancel();
switch (wait->clock)
{
@@ -307,23 +311,9 @@ int vlc_cond_timedwait(vlc_cond_t *wait, vlc_mutex_t *lock, mtime_t deadline)
DWORD delay = (total > 0x7fffffff) ? 0x7fffffff : total;
- if (wait->semaphore == NULL)
- { /* FIXME FIXME FIXME */
- vlc_mutex_unlock(lock);
- result = SleepEx((delay > 50) ? 50 : delay, TRUE);
- }
- else
- {
- InterlockedIncrement(&wait->waiters);
- vlc_mutex_unlock(lock);
- result = vlc_WaitForSingleObject(wait->semaphore, delay);
- }
- vlc_mutex_lock(lock);
-
- if (result == WAIT_IO_COMPLETION)
- vlc_testcancel();
-
- return (result == WAIT_TIMEOUT) ? ETIMEDOUT : 0;
+ if (vlc_cond_wait_delay(wait, lock, delay) == WAIT_TIMEOUT)
+ return ETIMEDOUT;
+ return 0;
}
/*** Semaphore ***/
More information about the vlc-commits
mailing list