Skip to content
Snippets Groups Projects
Commit 96bbc7a9 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont
Browse files

threads: remove no longer used vlc_rwlock_t

parent 76b3ad36
Branches master
No related tags found
1 merge request!967Remove read/write locks
Pipeline #164572 passed with stage
in 41 minutes and 28 seconds
......@@ -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.
......
......@@ -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
......
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment