mthread: add pthread spinlock emulation
This commit is contained in:
parent
25e6e2acbd
commit
dba634132e
|
|
@ -154,6 +154,7 @@ typedef mthread_mutexattr_t pthread_mutexattr_t;
|
||||||
typedef mthread_attr_t pthread_attr_t;
|
typedef mthread_attr_t pthread_attr_t;
|
||||||
typedef mthread_event_t pthread_event_t;
|
typedef mthread_event_t pthread_event_t;
|
||||||
typedef mthread_rwlock_t pthread_rwlock_t;
|
typedef mthread_rwlock_t pthread_rwlock_t;
|
||||||
|
typedef mthread_mutex_t pthread_spinlock_t; /* emulate spinlocks with mutexes */
|
||||||
|
|
||||||
/* LSC: No equivalent, so void* for now. */
|
/* LSC: No equivalent, so void* for now. */
|
||||||
typedef void *pthread_rwlockattr_t;
|
typedef void *pthread_rwlockattr_t;
|
||||||
|
|
@ -161,6 +162,8 @@ typedef void *pthread_rwlockattr_t;
|
||||||
#define PTHREAD_ONCE_INIT 0
|
#define PTHREAD_ONCE_INIT 0
|
||||||
#define PTHREAD_MUTEX_INITIALIZER ((pthread_mutex_t) -1)
|
#define PTHREAD_MUTEX_INITIALIZER ((pthread_mutex_t) -1)
|
||||||
#define PTHREAD_COND_INITIALIZER ((pthread_cond_t) -1)
|
#define PTHREAD_COND_INITIALIZER ((pthread_cond_t) -1)
|
||||||
|
#define PTHREAD_PROCESS_PRIVATE 0
|
||||||
|
#define PTHREAD_PROCESS_SHARED 1
|
||||||
|
|
||||||
__BEGIN_DECLS
|
__BEGIN_DECLS
|
||||||
/* allocate.c */
|
/* allocate.c */
|
||||||
|
|
@ -222,6 +225,13 @@ int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock);
|
||||||
int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock);
|
int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock);
|
||||||
int pthread_rwlock_unlock(pthread_rwlock_t *rwlock);
|
int pthread_rwlock_unlock(pthread_rwlock_t *rwlock);
|
||||||
|
|
||||||
|
/* pthread_compat.c */
|
||||||
|
int pthread_spin_destroy(pthread_spinlock_t *lock);
|
||||||
|
int pthread_spin_init(pthread_spinlock_t *lock, int UNUSED(pshared));
|
||||||
|
int pthread_spin_lock(pthread_spinlock_t *lock);
|
||||||
|
int pthread_spin_trylock(pthread_spinlock_t *lock);
|
||||||
|
int pthread_spin_unlock(pthread_spinlock_t *lock);
|
||||||
|
|
||||||
/* schedule.c */
|
/* schedule.c */
|
||||||
int pthread_yield(void);
|
int pthread_yield(void);
|
||||||
int sched_yield(void);
|
int sched_yield(void);
|
||||||
|
|
|
||||||
|
|
@ -139,6 +139,72 @@ int pthread_rwlock_init(pthread_rwlock_t *rwlock, pthread_rwlockattr_t *UNUSED(a
|
||||||
return mthread_rwlock_init(rwlock);
|
return mthread_rwlock_init(rwlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*===========================================================================*
|
||||||
|
* pthread_spin_destroy *
|
||||||
|
*===========================================================================*/
|
||||||
|
int pthread_spin_destroy(pthread_spinlock_t *lock)
|
||||||
|
{
|
||||||
|
pthread_mutex_t *mutex = (pthread_mutex_t*)lock;
|
||||||
|
|
||||||
|
if (PTHREAD_MUTEX_INITIALIZER == *mutex) {
|
||||||
|
mthread_mutex_init(mutex, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
return mthread_mutex_destroy(mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*===========================================================================*
|
||||||
|
* pthread_spin_init *
|
||||||
|
*===========================================================================*/
|
||||||
|
int pthread_spin_init(pthread_spinlock_t *lock, int UNUSED(pshared))
|
||||||
|
{
|
||||||
|
pthread_mutex_t *mutex = (pthread_mutex_t*)lock;
|
||||||
|
|
||||||
|
return mthread_mutex_init(mutex, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*===========================================================================*
|
||||||
|
* pthread_spin_lock *
|
||||||
|
*===========================================================================*/
|
||||||
|
int pthread_spin_lock(pthread_spinlock_t *lock)
|
||||||
|
{
|
||||||
|
pthread_mutex_t *mutex = (pthread_mutex_t*)lock;
|
||||||
|
|
||||||
|
if (PTHREAD_MUTEX_INITIALIZER == *mutex) {
|
||||||
|
mthread_mutex_init(mutex, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
return mthread_mutex_lock(mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*===========================================================================*
|
||||||
|
* pthread_spin_trylock *
|
||||||
|
*===========================================================================*/
|
||||||
|
int pthread_spin_trylock(pthread_spinlock_t *lock)
|
||||||
|
{
|
||||||
|
pthread_mutex_t *mutex = (pthread_mutex_t*)lock;
|
||||||
|
|
||||||
|
if (PTHREAD_MUTEX_INITIALIZER == *mutex) {
|
||||||
|
mthread_mutex_init(mutex, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
return mthread_mutex_trylock(mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*===========================================================================*
|
||||||
|
* pthread_spin_unlock *
|
||||||
|
*===========================================================================*/
|
||||||
|
int pthread_spin_unlock(pthread_spinlock_t *lock)
|
||||||
|
{
|
||||||
|
pthread_mutex_t *mutex = (pthread_mutex_t*)lock;
|
||||||
|
|
||||||
|
if (PTHREAD_MUTEX_INITIALIZER == *mutex) {
|
||||||
|
mthread_mutex_init(mutex, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
return mthread_mutex_unlock(mutex);
|
||||||
|
}
|
||||||
|
|
||||||
#if !defined(__weak_alias)
|
#if !defined(__weak_alias)
|
||||||
#error __weak_alias is required to compile the pthread compat library
|
#error __weak_alias is required to compile the pthread compat library
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user