[vlc-commits] [Git][videolan/vlc][master] threads: remove no longer used vlc_rwlock_t
Rémi Denis-Courmont (@Courmisch)
gitlab at videolan.org
Wed Dec 1 16:25:06 UTC 2021
Rémi Denis-Courmont pushed to branch master at VideoLAN / VLC
Commits:
96bbc7a9 by Rémi Denis-Courmont at 2021-12-01T15:52:08+00:00
threads: remove no longer used vlc_rwlock_t
- - - - -
3 changed files:
- include/vlc_threads.h
- src/libvlccore.sym
- src/misc/threads.c
Changes:
=====================================
include/vlc_threads.h
=====================================
@@ -511,64 +511,6 @@ VLC_API int vlc_sem_timedwait(vlc_sem_t *sem, vlc_tick_t deadline) VLC_USED;
/** @} */
-/**
- * \defgroup rwlock Read/write locks
- *
- * Read/write locks are a type of thread synchronization primitive meant to
- * protect access to data that is mostly read, and rarely written.
- * As long as no threads tries to acquire the lock for "writing", any number of
- * threads can acquire the lock for "reading".
- *
- * See also POSIX @c pthread_rwlock_t .
- *
- * @{
- */
-
-/**
- * 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;
-
-/**
- * Static initializer for (static) read/write lock.
- */
-#define VLC_STATIC_RWLOCK { VLC_STATIC_MUTEX, VLC_STATIC_COND, 0 }
-
-/**
- * Initializes a read/write lock.
- */
-VLC_API void vlc_rwlock_init(vlc_rwlock_t *);
-
-/**
- * Acquires a read/write lock for reading.
- *
- * \note Recursion is allowed.
- */
-VLC_API void vlc_rwlock_rdlock(vlc_rwlock_t *);
-
-/**
- * Acquires a read/write lock for writing. Recursion is not allowed.
- */
-VLC_API void vlc_rwlock_wrlock(vlc_rwlock_t *);
-
-/**
- * Releases a read/write lock.
- *
- * The calling thread must hold the lock. Otherwise behaviour is undefined.
- *
- * \note This function is not a cancellation point.
- */
-VLC_API void vlc_rwlock_unlock(vlc_rwlock_t *);
-
-/** @} */
-
#ifndef __cplusplus
/**
* One-time initialization.
=====================================
src/libvlccore.sym
=====================================
@@ -657,10 +657,6 @@ vlc_lrand48
vlc_mrand48
vlc_qsort
vlc_restorecancel
-vlc_rwlock_init
-vlc_rwlock_rdlock
-vlc_rwlock_unlock
-vlc_rwlock_wrlock
vlc_savecancel
vlc_sd_Create
vlc_sd_Destroy
=====================================
src/misc/threads.c
=====================================
@@ -320,71 +320,6 @@ int vlc_cond_timedwait_daytime(vlc_cond_t *cond, vlc_mutex_t *mutex,
return ret;
}
-/*** Generic read/write locks ***/
-/* NOTE:
- * lock->state is a signed long integer:
- * - The sign bit is set when the lock is held for writing.
- * - The other bits code the number of times the lock is held for reading.
- * Consequently:
- * - The value is negative if and only if the lock is held for writing.
- * - The value is zero if and only if the lock is not held at all.
- */
-#define READER_MASK LONG_MAX
-#define WRITER_BIT LONG_MIN
-
-void vlc_rwlock_init (vlc_rwlock_t *lock)
-{
- vlc_mutex_init (&lock->mutex);
- vlc_cond_init (&lock->wait);
- lock->state = 0;
-}
-
-void vlc_rwlock_rdlock (vlc_rwlock_t *lock)
-{
- vlc_mutex_lock (&lock->mutex);
- /* Recursive read-locking is allowed.
- * Ensure that there is no active writer. */
- while (lock->state < 0)
- {
- assert (lock->state == WRITER_BIT);
- vlc_cond_wait (&lock->wait, &lock->mutex);
- }
- if (unlikely(lock->state >= READER_MASK))
- abort (); /* An overflow is certainly a recursion bug. */
- lock->state++;
- vlc_mutex_unlock (&lock->mutex);
-}
-
-void vlc_rwlock_wrlock (vlc_rwlock_t *lock)
-{
- vlc_mutex_lock (&lock->mutex);
- /* Wait until nobody owns the lock in any way. */
- while (lock->state != 0)
- vlc_cond_wait (&lock->wait, &lock->mutex);
- lock->state = WRITER_BIT;
- vlc_mutex_unlock (&lock->mutex);
-}
-
-void vlc_rwlock_unlock (vlc_rwlock_t *lock)
-{
- vlc_mutex_lock (&lock->mutex);
- if (lock->state < 0)
- { /* Write unlock */
- assert (lock->state == WRITER_BIT);
- /* Let reader and writer compete. OS scheduler decides who wins. */
- lock->state = 0;
- vlc_cond_broadcast (&lock->wait);
- }
- else
- { /* Read unlock */
- assert (lock->state > 0);
- /* If there are no readers left, wake up one pending writer. */
- if (--lock->state == 0)
- vlc_cond_signal (&lock->wait);
- }
- vlc_mutex_unlock (&lock->mutex);
-}
-
/*** Generic semaphores ***/
void vlc_sem_init (vlc_sem_t *sem, unsigned value)
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/96bbc7a93f89ce5fe86562c98127f22d8a249fe6
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/96bbc7a93f89ce5fe86562c98127f22d8a249fe6
You're receiving this email because of your account on code.videolan.org.
More information about the vlc-commits
mailing list