[vlc-commits] Win32: remove vlc_rwlock_t.writers - not really needed

Rémi Denis-Courmont git at videolan.org
Sat Jan 28 12:59:23 CET 2012


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Jan 28 13:58:42 2012 +0200| [99a46209e681f1463a98788916f1db7adfcc1407] | committer: Rémi Denis-Courmont

Win32: remove vlc_rwlock_t.writers - not really needed

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=99a46209e681f1463a98788916f1db7adfcc1407
---

 include/vlc_threads.h |    6 ++----
 src/os2/thread.c      |   15 ++-------------
 src/win32/thread.c    |   16 +++-------------
 3 files changed, 7 insertions(+), 30 deletions(-)

diff --git a/include/vlc_threads.h b/include/vlc_threads.h
index ca7c180..ebf94e2 100644
--- a/include/vlc_threads.h
+++ b/include/vlc_threads.h
@@ -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;
diff --git a/src/os2/thread.c b/src/os2/thread.c
index 3f08658..e51b086 100644
--- a/src/os2/thread.c
+++ b/src/os2/thread.c
@@ -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);
diff --git a/src/win32/thread.c b/src/win32/thread.c
index cd4c454..d16f4fe 100644
--- a/src/win32/thread.c
+++ b/src/win32/thread.c
@@ -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);



More information about the vlc-commits mailing list