Files
mars-nwe/include/core/spinlock.h

55 lines
1.0 KiB
C

#ifndef MARS_NWE_CORE_SPINLOCK_H
#define MARS_NWE_CORE_SPINLOCK_H
#include <pthread.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* Linux userspace backend for NSS runtime spin locks.
*
* The imported NSS common-layer headers were written for NetWare/NLM and
* Linux-kernel style spinlock APIs. mars-nwe now targets Linux userspace, so
* keep the primitive in libnwcore and map it directly to POSIX pthread
* spinlocks instead of carrying a fake NWFS-local shim.
*/
typedef pthread_spinlock_t spinlock_t;
static inline void
spin_lock_init(spinlock_t *lock)
{
(void)pthread_spin_init(lock, PTHREAD_PROCESS_PRIVATE);
}
static inline void
spin_lock_destroy(spinlock_t *lock)
{
(void)pthread_spin_destroy(lock);
}
static inline void
spin_lock(spinlock_t *lock)
{
(void)pthread_spin_lock(lock);
}
static inline void
spin_unlock(spinlock_t *lock)
{
(void)pthread_spin_unlock(lock);
}
static inline int
spin_trylock(spinlock_t *lock)
{
return pthread_spin_trylock(lock) == 0;
}
#ifdef __cplusplus
}
#endif
#endif /* MARS_NWE_CORE_SPINLOCK_H */