0484 core: add Linux pthread spinlock backend for NSS runtime

This commit is contained in:
Mario Fetka
2026-06-13 16:44:58 +00:00
parent 6ddb0fb9de
commit a76f0c8999
8 changed files with 122 additions and 22 deletions

54
include/core/spinlock.h Normal file
View File

@@ -0,0 +1,54 @@
#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 */