RRG-Proxmark3/client/src/pthread_spin_lock_shim.h
iceman1001 5de4dd68e5
Some checks failed
MacOS Build and Test / macos-make-btaddon (push) Has been cancelled
MacOS Build and Test / macos-cmake (push) Has been cancelled
Ubuntu Build and Test / ubuntu-make (push) Has been cancelled
Ubuntu Build and Test / ubuntu-make-btaddon (push) Has been cancelled
CodeQL / Analyze (push) Has been cancelled
MacOS Build and Test / macos-make (push) Has been cancelled
Ubuntu Build and Test / ubuntu-cmake (push) Has been cancelled
Windows Build and Test / proxspace (push) Has been cancelled
Windows Build and Test / wsl (push) Has been cancelled
text
2025-06-22 20:34:54 +02:00

55 lines
1.1 KiB
C

/*
Required imports:
#include <errno.h>
*/
#ifndef PTHREAD_SPIN_LOCK_SHIM
#define PTHREAD_SPIN_LOCK_SHIM
typedef int pthread_spinlock_t;
#ifndef PTHREAD_PROCESS_SHARED
# define PTHREAD_PROCESS_SHARED 1
#endif
#ifndef PTHREAD_PROCESS_PRIVATE
# define PTHREAD_PROCESS_PRIVATE 2
#endif
static inline int pthread_spin_init(pthread_spinlock_t *lock, int pshared) {
__asm__ __volatile__("" ::: "memory");
*lock = 0;
return 0;
}
static inline int pthread_spin_destroy(pthread_spinlock_t *lock) {
return 0;
}
static inline int pthread_spin_lock(pthread_spinlock_t *lock) {
while (1) {
int i;
for (i = 0; i < 10000; i++) {
if (__sync_bool_compare_and_swap(lock, 0, 1)) {
return 0;
}
}
sched_yield();
}
}
static inline int pthread_spin_trylock(pthread_spinlock_t *lock) {
if (__sync_bool_compare_and_swap(lock, 0, 1)) {
return 0;
}
return 16; // EBUSY;
}
static inline int pthread_spin_unlock(pthread_spinlock_t *lock) {
__asm__ __volatile__("" ::: "memory");
*lock = 0;
return 0;
}
#endif