Commit 99a46209 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Win32: remove vlc_rwlock_t.writers - not really needed

parent cc40da80
......@@ -166,11 +166,10 @@ typedef struct
vlc_mutex_t mutex;
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, 0, 0, 0 }
{ VLC_STATIC_MUTEX, VLC_STATIC_COND, 0, 0 }
typedef struct vlc_threadvar *vlc_threadvar_t;
typedef struct vlc_timer *vlc_timer_t;
......@@ -215,11 +214,10 @@ typedef struct
vlc_mutex_t mutex;
vlc_cond_t wait;
unsigned long readers;
unsigned long writers;
int writer;
} vlc_rwlock_t;
#define VLC_STATIC_RWLOCK \
{ VLC_STATIC_MUTEX, VLC_STATIC_COND, 0, 0, 0 }
{ VLC_STATIC_MUTEX, VLC_STATIC_COND, 0, 0 }
typedef struct vlc_threadvar *vlc_threadvar_t;
typedef struct vlc_timer *vlc_timer_t;
......
......@@ -434,7 +434,6 @@ void vlc_rwlock_init (vlc_rwlock_t *lock)
vlc_mutex_init (&lock->mutex);
vlc_cond_init (&lock->wait);
lock->readers = 0; /* active readers */
lock->writers = 0; /* waiting or active writers */
lock->writer = 0; /* ID of active writer */
}
......@@ -447,13 +446,7 @@ void vlc_rwlock_destroy (vlc_rwlock_t *lock)
void vlc_rwlock_rdlock (vlc_rwlock_t *lock)
{
vlc_mutex_lock (&lock->mutex);
/* Recursive read-locking is allowed. With the infos available:
* - the loosest possible condition (no active writer) is:
* (lock->writer != 0)
* - the strictest possible condition is:
* (lock->writer != 0 || (lock->readers == 0 && lock->writers > 0))
* or (lock->readers == 0 && (lock->writer != 0 || lock->writers > 0))
*/
/* Recursive read-locking is allowed. */
while (lock->writer != 0)
{
assert (lock->readers == 0);
......@@ -471,7 +464,7 @@ static void vlc_rwlock_rdunlock (vlc_rwlock_t *lock)
assert (lock->readers > 0);
/* If there are no readers left, wake up a writer. */
if (--lock->readers == 0 && lock->writers > 0)
if (--lock->readers == 0)
vlc_cond_signal (&lock->wait);
vlc_mutex_unlock (&lock->mutex);
}
......@@ -479,13 +472,9 @@ static void vlc_rwlock_rdunlock (vlc_rwlock_t *lock)
void vlc_rwlock_wrlock (vlc_rwlock_t *lock)
{
vlc_mutex_lock (&lock->mutex);
if (unlikely(lock->writers == ULONG_MAX))
abort ();
lock->writers++;
/* Wait until nobody owns the lock in either way. */
while ((lock->readers > 0) || (lock->writer != 0))
vlc_cond_wait (&lock->wait, &lock->mutex);
lock->writers--;
assert (lock->writer == 0);
lock->writer = _gettid ();
vlc_mutex_unlock (&lock->mutex);
......
......@@ -388,7 +388,6 @@ void vlc_rwlock_init (vlc_rwlock_t *lock)
vlc_mutex_init (&lock->mutex);
vlc_cond_init (&lock->wait);
lock->readers = 0; /* active readers */
lock->writers = 0; /* waiting writers */
lock->writer = 0; /* ID of active writer */
}
......@@ -401,13 +400,8 @@ void vlc_rwlock_destroy (vlc_rwlock_t *lock)
void vlc_rwlock_rdlock (vlc_rwlock_t *lock)
{
vlc_mutex_lock (&lock->mutex);
/* Recursive read-locking is allowed. With the infos available:
* - the loosest possible condition (no active writer) is:
* (lock->writer != 0)
* - the strictest possible condition is:
* (lock->writer != 0 || (lock->readers == 0 && lock->writers > 0))
* or (lock->readers == 0 && (lock->writer != 0 || lock->writers > 0))
*/
/* Recursive read-locking is allowed. We only need to ensure that there is
* no active writer. */
while (lock->writer != 0)
{
assert (lock->readers == 0);
......@@ -425,7 +419,7 @@ static void vlc_rwlock_rdunlock (vlc_rwlock_t *lock)
assert (lock->readers > 0);
/* If there are no readers left, wake up a writer. */
if (--lock->readers == 0 && lock->writers > 0)
if (--lock->readers == 0)
vlc_cond_signal (&lock->wait);
vlc_mutex_unlock (&lock->mutex);
}
......@@ -433,13 +427,9 @@ static void vlc_rwlock_rdunlock (vlc_rwlock_t *lock)
void vlc_rwlock_wrlock (vlc_rwlock_t *lock)
{
vlc_mutex_lock (&lock->mutex);
if (unlikely(lock->writers == ULONG_MAX))
abort ();
lock->writers++;
/* Wait until nobody owns the lock in either way. */
while ((lock->readers > 0) || (lock->writer != 0))
vlc_cond_wait (&lock->wait, &lock->mutex);
lock->writers--;
assert (lock->writer == 0);
lock->writer = GetCurrentThreadId ();
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