Commit 1ecccba1 authored by Josh Kunz's avatar Josh Kunz

Add OSX spinlock adpater

Add a compat header that implements the POSIX spinlock API using OSX's
libkern/OSAtomic.h. OSX is supposedly POSIX compliant, but it appears to
not implement spinlocks as part of it's pthread API. Only works with
OS version after 10.4 which should be pretty much every OSX device out
there.
parent 3ef76466
#ifndef __LIBCAP_COMPAT_INTERNAL_OSX_USER_H__
#define __LIBCAP_COMPAT_INTERNAL_OSX_USER_H__
#include <Availability.h>
#ifdef __MAC_OS_X_VERSION_MIN_REQUIRED
#if __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_4
#error "OSSpinLock only supported from on OSX 10.4+"
#endif
#else
#error "__MAC_OS_X_VERSION_MIN_REQUIRED macro not supported on this platform"
#endif
#include <assert.h>
#include <libkern/OSAtomic.h>
typedef OSSpinLock pthread_spinlock_t;
static int pthread_spin_init(pthread_spinlock_t *lock, int pshared) {
assert(pshared == PTHREAD_PROCESS_PRIVATE &&
"PTHREAD_PROCESS_SHARED not supported on OSX");
*lock = OS_SPINLOCK_INIT;
return 0;
}
static int pthread_spin_destroy(pthread_spinlock_t *lock) { return 0; }
static int pthread_spin_lock(pthread_spinlock_t *lock) {
OSSpinLockLock(lock);
return 0;
}
/* OSSpinLockTry returns false when it fails to acquire the lock, seems
* to be equivalent to EBUSY under the standard API */
static int pthread_spin_trylock(pthread_spinlock_t *lock) {
if (OSSpinLockTry(lock) == true) {
return 0;
} else {
return EBUSY;
}
}
static int pthread_spin_unlock(pthread_spinlock_t *lock) {
OSSpinLockUnlock(lock);
return 0;
}
#endif
......@@ -17,6 +17,10 @@
#include <string.h>
#include <errno.h>
#ifdef __APPLE__
#include "compat_internal/osx_user.h"
#endif
/**
* Mutex support. Follow kernel return convention.
*/
......@@ -86,6 +90,8 @@ static inline void __cap_cache_free(cap_cache_t *cache, void *obj)
g_slice_free1(cache->size, obj);
}
/**
* Spinlocks. An array of pthread spinlocks. We have one for each L1
* cache line. This is stupid because glibc x86 pthread_spinlock_t is
......
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