[vlc-commits] threads: use common vlc_rwlock_t on all platforms

Rémi Denis-Courmont git at videolan.org
Wed Jan 13 17:55:13 UTC 2021


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue Dec 22 22:37:31 2020 +0200| [4bf5c6f766fe0750102aa28cba1e62237ef4bc1c] | committer: Rémi Denis-Courmont

threads: use common vlc_rwlock_t on all platforms

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

 include/vlc_threads.h | 32 ++++++++++----------------------
 src/misc/threads.c    |  4 ----
 src/posix/thread.c    | 30 ------------------------------
 3 files changed, 10 insertions(+), 56 deletions(-)

diff --git a/include/vlc_threads.h b/include/vlc_threads.h
index 21f4e46c27..2054e632f0 100644
--- a/include/vlc_threads.h
+++ b/include/vlc_threads.h
@@ -60,7 +60,6 @@ typedef struct vlc_thread *vlc_thread_t;
 # define VLC_THREAD_CANCELED NULL
 
 # define LIBVLC_NEED_SLEEP
-#define LIBVLC_NEED_RWLOCK
 typedef struct vlc_threadvar *vlc_threadvar_t;
 typedef struct vlc_timer *vlc_timer_t;
 
@@ -89,7 +88,6 @@ static inline int vlc_poll(struct pollfd *fds, unsigned nfds, int timeout)
 typedef struct vlc_thread *vlc_thread_t;
 #define VLC_THREAD_CANCELED NULL
 
-#define LIBVLC_NEED_RWLOCK
 typedef struct vlc_threadvar *vlc_threadvar_t;
 typedef struct vlc_timer *vlc_timer_t;
 
@@ -130,7 +128,6 @@ static inline int vlc_poll (struct pollfd *fds, unsigned nfds, int timeout)
 # include <poll.h>
 # define LIBVLC_USE_PTHREAD_CLEANUP   1
 # define LIBVLC_NEED_SLEEP
-# define LIBVLC_NEED_RWLOCK
 
 typedef struct vlc_thread *vlc_thread_t;
 #define VLC_THREAD_CANCELED NULL
@@ -191,22 +188,6 @@ typedef struct
  */
 #define VLC_THREAD_CANCELED PTHREAD_CANCELED
 
-/**
- * Read/write lock.
- *
- * Storage space for a slim reader/writer lock.
- *
- * \ingroup rwlock
- */
-typedef pthread_rwlock_t vlc_rwlock_t;
-
-/**
- * Static initializer for (static) read/write lock.
- *
- * \ingroup rwlock
- */
-#define VLC_STATIC_RWLOCK PTHREAD_RWLOCK_INITIALIZER
-
 /**
  * Thread-local key handle.
  *
@@ -544,15 +525,22 @@ VLC_API int vlc_sem_timedwait(vlc_sem_t *sem, vlc_tick_t deadline) VLC_USED;
  * @{
  */
 
-#ifdef LIBVLC_NEED_RWLOCK
+/**
+ * Read/write lock.
+ *
+ * Storage space for a slim reader/writer lock.
+ */
 typedef struct vlc_rwlock
 {
     vlc_mutex_t   mutex;
     vlc_cond_t    wait;
     long          state;
 } vlc_rwlock_t;
-# define VLC_STATIC_RWLOCK { VLC_STATIC_MUTEX, VLC_STATIC_COND, 0 }
-#endif
+
+/**
+ * Static initializer for (static) read/write lock.
+ */
+#define VLC_STATIC_RWLOCK { VLC_STATIC_MUTEX, VLC_STATIC_COND, 0 }
 
 /**
  * Initializes a read/write lock.
diff --git a/src/misc/threads.c b/src/misc/threads.c
index 15311b5214..460fabc3c8 100644
--- a/src/misc/threads.c
+++ b/src/misc/threads.c
@@ -372,10 +372,7 @@ int vlc_cond_timedwait_daytime(vlc_cond_t *cond, vlc_mutex_t *mutex,
     return ret;
 }
 
-#ifdef LIBVLC_NEED_RWLOCK
 /*** Generic read/write locks ***/
-#include <stdlib.h>
-#include <limits.h>
 /* NOTE:
  * lock->state is a signed long integer:
  *  - The sign bit is set when the lock is held for writing.
@@ -444,7 +441,6 @@ void vlc_rwlock_unlock (vlc_rwlock_t *lock)
     }
     vlc_mutex_unlock (&lock->mutex);
 }
-#endif /* LIBVLC_NEED_RWLOCK */
 
 /*** Generic semaphores ***/
 
diff --git a/src/posix/thread.c b/src/posix/thread.c
index 91eab74716..d617bd7292 100644
--- a/src/posix/thread.c
+++ b/src/posix/thread.c
@@ -103,36 +103,6 @@ vlc_thread_fatal (const char *action, int error,
 # define VLC_THREAD_ASSERT( action ) ((void)val)
 #endif
 
-void vlc_rwlock_init (vlc_rwlock_t *lock)
-{
-    if (unlikely(pthread_rwlock_init (lock, NULL)))
-        abort ();
-}
-
-void vlc_rwlock_destroy (vlc_rwlock_t *lock)
-{
-    int val = pthread_rwlock_destroy (lock);
-    VLC_THREAD_ASSERT ("destroying R/W lock");
-}
-
-void vlc_rwlock_rdlock (vlc_rwlock_t *lock)
-{
-    int val = pthread_rwlock_rdlock (lock);
-    VLC_THREAD_ASSERT ("acquiring R/W lock for reading");
-}
-
-void vlc_rwlock_wrlock (vlc_rwlock_t *lock)
-{
-    int val = pthread_rwlock_wrlock (lock);
-    VLC_THREAD_ASSERT ("acquiring R/W lock for writing");
-}
-
-void vlc_rwlock_unlock (vlc_rwlock_t *lock)
-{
-    int val = pthread_rwlock_unlock (lock);
-    VLC_THREAD_ASSERT ("releasing R/W lock");
-}
-
 int vlc_threadvar_create (vlc_threadvar_t *key, void (*destr) (void *))
 {
     return pthread_key_create (key, destr);



More information about the vlc-commits mailing list