[vlc-commits] Win32: use only one condition variable per R/W lock
Rémi Denis-Courmont
git at videolan.org
Sat Aug 20 19:31:58 CEST 2011
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Aug 20 16:39:09 2011 +0300| [6fdf44fd13f5c24efb7ac5a593e967d02449b665] | committer: Rémi Denis-Courmont
Win32: use only one condition variable per R/W lock
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=6fdf44fd13f5c24efb7ac5a593e967d02449b665
---
configure.ac | 2 +-
include/vlc_threads.h | 5 ++---
src/win32/thread.c | 16 ++++++----------
3 files changed, 9 insertions(+), 14 deletions(-)
diff --git a/configure.ac b/configure.ac
index 89dce2b..bd9a073 100644
--- a/configure.ac
+++ b/configure.ac
@@ -320,7 +320,7 @@ case "${host_os}" in
*mingw32* | *cygwin* | *wince* | *mingwce*)
AC_CHECK_TOOL(WINDRES, windres, :)
AC_CHECK_TOOL(OBJCOPY, objcopy, :)
- AC_DEFINE([_WIN32_WINNT], 0x0501, [Define to '0x0501' for Windows XP APIs.])
+ AC_DEFINE([_WIN32_WINNT], 0x0600, [Define to '0x0600' for Windows Vista APIs.])
AC_DEFINE([_WIN32_IE], 0x0501, [Define to '0x0501' for IE 5.01 (and shell) APIs.])
case "${host_os}" in
diff --git a/include/vlc_threads.h b/include/vlc_threads.h
index fea79be..ddaeff1 100644
--- a/include/vlc_threads.h
+++ b/include/vlc_threads.h
@@ -151,14 +151,13 @@ typedef HANDLE vlc_sem_t;
typedef struct
{
vlc_mutex_t mutex;
- vlc_cond_t read_wait;
- vlc_cond_t write_wait;
+ vlc_cond_t wait;
unsigned long readers;
unsigned long writers;
DWORD writer;
} vlc_rwlock_t;
#define VLC_STATIC_RWLOCK \
- { VLC_STATIC_MUTEX, VLC_STATIC_COND, VLC_STATIC_COND, 0, 0, 0 }
+ { VLC_STATIC_MUTEX, VLC_STATIC_COND, 0, 0, 0 }
typedef struct vlc_threadvar *vlc_threadvar_t;
typedef struct vlc_timer *vlc_timer_t;
diff --git a/src/win32/thread.c b/src/win32/thread.c
index 5b5753c..1dfeef6 100644
--- a/src/win32/thread.c
+++ b/src/win32/thread.c
@@ -384,8 +384,7 @@ void vlc_sem_wait (vlc_sem_t *sem)
void vlc_rwlock_init (vlc_rwlock_t *lock)
{
vlc_mutex_init (&lock->mutex);
- vlc_cond_init (&lock->read_wait);
- vlc_cond_init (&lock->write_wait);
+ vlc_cond_init (&lock->wait);
lock->readers = 0; /* active readers */
lock->writers = 0; /* waiting writers */
lock->writer = 0; /* ID of active writer */
@@ -393,8 +392,7 @@ void vlc_rwlock_init (vlc_rwlock_t *lock)
void vlc_rwlock_destroy (vlc_rwlock_t *lock)
{
- vlc_cond_destroy (&lock->read_wait);
- vlc_cond_destroy (&lock->write_wait);
+ vlc_cond_destroy (&lock->wait);
vlc_mutex_destroy (&lock->mutex);
}
@@ -411,7 +409,7 @@ void vlc_rwlock_rdlock (vlc_rwlock_t *lock)
while (lock->writer != 0)
{
assert (lock->readers == 0);
- vlc_cond_wait (&lock->read_wait, &lock->mutex);
+ vlc_cond_wait (&lock->wait, &lock->mutex);
}
if (unlikely(lock->readers == ULONG_MAX))
abort ();
@@ -426,7 +424,7 @@ static void vlc_rwlock_rdunlock (vlc_rwlock_t *lock)
/* If there are no readers left, wake up a writer. */
if (--lock->readers == 0 && lock->writers > 0)
- vlc_cond_signal (&lock->write_wait);
+ vlc_cond_signal (&lock->wait);
vlc_mutex_unlock (&lock->mutex);
}
@@ -438,7 +436,7 @@ void vlc_rwlock_wrlock (vlc_rwlock_t *lock)
lock->writers++;
/* Wait until nobody owns the lock in either way. */
while ((lock->readers > 0) || (lock->writer != 0))
- vlc_cond_wait (&lock->write_wait, &lock->mutex);
+ vlc_cond_wait (&lock->wait, &lock->mutex);
lock->writers--;
assert (lock->writer == 0);
lock->writer = GetCurrentThreadId ();
@@ -453,9 +451,7 @@ static void vlc_rwlock_wrunlock (vlc_rwlock_t *lock)
lock->writer = 0; /* Write unlock */
/* Let reader and writer compete. Scheduler decides who wins. */
- if (lock->writers > 0)
- vlc_cond_signal (&lock->write_wait);
- vlc_cond_broadcast (&lock->read_wait);
+ vlc_cond_broadcast (&lock->wait);
vlc_mutex_unlock (&lock->mutex);
}
More information about the vlc-commits
mailing list