[vlc-commits] Win32: emulate static condition variables
Rémi Denis-Courmont
git at videolan.org
Thu Aug 18 17:37:15 CEST 2011
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Aug 18 18:14:41 2011 +0300| [4707b4f4ac4b643900210be6169913f7d550f2af] | committer: Rémi Denis-Courmont
Win32: emulate static condition variables
This is really poor implementation, but it is not really used.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=4707b4f4ac4b643900210be6169913f7d550f2af
---
include/vlc_threads.h | 1 +
src/win32/thread.c | 29 ++++++++++++++++++++++-------
2 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/include/vlc_threads.h b/include/vlc_threads.h
index dfe4359..fea79be 100644
--- a/include/vlc_threads.h
+++ b/include/vlc_threads.h
@@ -144,6 +144,7 @@ typedef struct
HANDLE handle;
unsigned clock;
} vlc_cond_t;
+#define VLC_STATIC_COND { 0, 0, 0 }
typedef HANDLE vlc_sem_t;
diff --git a/src/win32/thread.c b/src/win32/thread.c
index 6831cbe..99e54b5 100644
--- a/src/win32/thread.c
+++ b/src/win32/thread.c
@@ -232,8 +232,8 @@ void vlc_mutex_unlock (vlc_mutex_t *p_mutex)
/*** Condition variables ***/
enum
{
+ CLOCK_REALTIME=0, /* must be zero for VLC_STATIC_COND */
CLOCK_MONOTONIC,
- CLOCK_REALTIME,
};
static void vlc_cond_init_common (vlc_cond_t *p_condvar, unsigned clock)
@@ -262,16 +262,19 @@ void vlc_cond_destroy (vlc_cond_t *p_condvar)
void vlc_cond_signal (vlc_cond_t *p_condvar)
{
- /* NOTE: This will cause a broadcast, that is wrong.
- * This will also wake up the next waiting thread if no threads are yet
- * waiting, which is also wrong. However both of these issues are allowed
- * by the provision for spurious wakeups. Better have too many wakeups
- * than too few (= deadlocks). */
- SetEvent (p_condvar->handle);
+ if (!p_condvar->handle)
+ return;
+
+ /* This is suboptimal but works. */
+ vlc_cond_broadcast (p_condvar);
}
void vlc_cond_broadcast (vlc_cond_t *p_condvar)
{
+ if (!p_condvar->handle)
+ return;
+
+ /* Wake all threads up (as the event HANDLE has manual reset) */
SetEvent (p_condvar->handle);
}
@@ -279,6 +282,12 @@ void vlc_cond_wait (vlc_cond_t *p_condvar, vlc_mutex_t *p_mutex)
{
DWORD result;
+ if (!p_condvar->handle)
+ { /* FIXME FIXME FIXME */
+ msleep (50000);
+ return;
+ }
+
do
{
vlc_testcancel ();
@@ -296,6 +305,12 @@ int vlc_cond_timedwait (vlc_cond_t *p_condvar, vlc_mutex_t *p_mutex,
{
DWORD result;
+ if (!p_condvar->handle)
+ { /* FIXME FIXME FIXME */
+ msleep (50000);
+ return 0;
+ }
+
do
{
vlc_testcancel ();
More information about the vlc-commits
mailing list