[vlc-devel] [PATCH 1/3] threads: use common vlc_rwlock_t on all platforms

remi at remlab.net remi at remlab.net
Tue Jan 12 17:30:31 UTC 2021


From: RĂ©mi Denis-Courmont <remi at remlab.net>

---
 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 39705b008a..76c7049f00 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);
-- 
2.30.0



More information about the vlc-devel mailing list