Commit 88e839df authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Do not blindly favor writers

This fixes a corner case:
A: rdlock -> OK
B: wrlock -> sleeps
A: rdlock -> dead lock
parent 5662f3a4
...@@ -320,7 +320,7 @@ void vlc_rwlock_destroy (vlc_rwlock_t *lock) ...@@ -320,7 +320,7 @@ void vlc_rwlock_destroy (vlc_rwlock_t *lock)
void vlc_rwlock_rdlock (vlc_rwlock_t *lock) void vlc_rwlock_rdlock (vlc_rwlock_t *lock)
{ {
vlc_mutex_lock (&lock->mutex); vlc_mutex_lock (&lock->mutex);
while (lock->writers > 0) /* Favor writers to avoid starving */ while (lock->writer != 0)
vlc_cond_wait (&lock->read_wait, &lock->mutex); vlc_cond_wait (&lock->read_wait, &lock->mutex);
if (lock->readers == ULONG_MAX) if (lock->readers == ULONG_MAX)
abort (); abort ();
......
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