Commit 4bf5c6f7 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

threads: use common vlc_rwlock_t on all platforms

parent 222367a0
......@@ -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.
......
......@@ -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 ***/
......
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment