Commit 6fdf44fd authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Win32: use only one condition variable per R/W lock

parent fd42ed01
...@@ -320,7 +320,7 @@ case "${host_os}" in ...@@ -320,7 +320,7 @@ case "${host_os}" in
*mingw32* | *cygwin* | *wince* | *mingwce*) *mingw32* | *cygwin* | *wince* | *mingwce*)
AC_CHECK_TOOL(WINDRES, windres, :) AC_CHECK_TOOL(WINDRES, windres, :)
AC_CHECK_TOOL(OBJCOPY, objcopy, :) 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.]) AC_DEFINE([_WIN32_IE], 0x0501, [Define to '0x0501' for IE 5.01 (and shell) APIs.])
case "${host_os}" in case "${host_os}" in
......
...@@ -151,14 +151,13 @@ typedef HANDLE vlc_sem_t; ...@@ -151,14 +151,13 @@ typedef HANDLE vlc_sem_t;
typedef struct typedef struct
{ {
vlc_mutex_t mutex; vlc_mutex_t mutex;
vlc_cond_t read_wait; vlc_cond_t wait;
vlc_cond_t write_wait;
unsigned long readers; unsigned long readers;
unsigned long writers; unsigned long writers;
DWORD writer; DWORD writer;
} vlc_rwlock_t; } vlc_rwlock_t;
#define VLC_STATIC_RWLOCK \ #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_threadvar *vlc_threadvar_t;
typedef struct vlc_timer *vlc_timer_t; typedef struct vlc_timer *vlc_timer_t;
......
...@@ -384,8 +384,7 @@ void vlc_sem_wait (vlc_sem_t *sem) ...@@ -384,8 +384,7 @@ void vlc_sem_wait (vlc_sem_t *sem)
void vlc_rwlock_init (vlc_rwlock_t *lock) void vlc_rwlock_init (vlc_rwlock_t *lock)
{ {
vlc_mutex_init (&lock->mutex); vlc_mutex_init (&lock->mutex);
vlc_cond_init (&lock->read_wait); vlc_cond_init (&lock->wait);
vlc_cond_init (&lock->write_wait);
lock->readers = 0; /* active readers */ lock->readers = 0; /* active readers */
lock->writers = 0; /* waiting writers */ lock->writers = 0; /* waiting writers */
lock->writer = 0; /* ID of active writer */ lock->writer = 0; /* ID of active writer */
...@@ -393,8 +392,7 @@ void vlc_rwlock_init (vlc_rwlock_t *lock) ...@@ -393,8 +392,7 @@ void vlc_rwlock_init (vlc_rwlock_t *lock)
void vlc_rwlock_destroy (vlc_rwlock_t *lock) void vlc_rwlock_destroy (vlc_rwlock_t *lock)
{ {
vlc_cond_destroy (&lock->read_wait); vlc_cond_destroy (&lock->wait);
vlc_cond_destroy (&lock->write_wait);
vlc_mutex_destroy (&lock->mutex); vlc_mutex_destroy (&lock->mutex);
} }
...@@ -411,7 +409,7 @@ void vlc_rwlock_rdlock (vlc_rwlock_t *lock) ...@@ -411,7 +409,7 @@ void vlc_rwlock_rdlock (vlc_rwlock_t *lock)
while (lock->writer != 0) while (lock->writer != 0)
{ {
assert (lock->readers == 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)) if (unlikely(lock->readers == ULONG_MAX))
abort (); abort ();
...@@ -426,7 +424,7 @@ static void vlc_rwlock_rdunlock (vlc_rwlock_t *lock) ...@@ -426,7 +424,7 @@ static void vlc_rwlock_rdunlock (vlc_rwlock_t *lock)
/* If there are no readers left, wake up a writer. */ /* If there are no readers left, wake up a writer. */
if (--lock->readers == 0 && lock->writers > 0) if (--lock->readers == 0 && lock->writers > 0)
vlc_cond_signal (&lock->write_wait); vlc_cond_signal (&lock->wait);
vlc_mutex_unlock (&lock->mutex); vlc_mutex_unlock (&lock->mutex);
} }
...@@ -438,7 +436,7 @@ void vlc_rwlock_wrlock (vlc_rwlock_t *lock) ...@@ -438,7 +436,7 @@ void vlc_rwlock_wrlock (vlc_rwlock_t *lock)
lock->writers++; lock->writers++;
/* Wait until nobody owns the lock in either way. */ /* Wait until nobody owns the lock in either way. */
while ((lock->readers > 0) || (lock->writer != 0)) while ((lock->readers > 0) || (lock->writer != 0))
vlc_cond_wait (&lock->write_wait, &lock->mutex); vlc_cond_wait (&lock->wait, &lock->mutex);
lock->writers--; lock->writers--;
assert (lock->writer == 0); assert (lock->writer == 0);
lock->writer = GetCurrentThreadId (); lock->writer = GetCurrentThreadId ();
...@@ -453,9 +451,7 @@ static void vlc_rwlock_wrunlock (vlc_rwlock_t *lock) ...@@ -453,9 +451,7 @@ static void vlc_rwlock_wrunlock (vlc_rwlock_t *lock)
lock->writer = 0; /* Write unlock */ lock->writer = 0; /* Write unlock */
/* Let reader and writer compete. Scheduler decides who wins. */ /* Let reader and writer compete. Scheduler decides who wins. */
if (lock->writers > 0) vlc_cond_broadcast (&lock->wait);
vlc_cond_signal (&lock->write_wait);
vlc_cond_broadcast (&lock->read_wait);
vlc_mutex_unlock (&lock->mutex); vlc_mutex_unlock (&lock->mutex);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment