Skip to content

Commit

Permalink
Add spinlock support for OSX
Browse files Browse the repository at this point in the history
  • Loading branch information
vigsterkr committed May 10, 2013
1 parent 56ee307 commit 5a10d5e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/configure
Expand Up @@ -1050,17 +1050,30 @@ test_spinlocks()
return
fi

if darwin
then
cat > $TMPC << EOF
#include <pthread.h>
#include <libkern/OSAtomic.h>
int main(void)
{
volatile OSSpinLock lock;
OSSpinLockTry(&lock);
return 0;
}
EOF
else
cat > $TMPC << EOF
#include <pthread.h>
int main(void)
{
volatile pthread_spinlock_t lock;
pthread_spin_init(&lock, 0);
return 0;
}
EOF
fi

echocheck "Posix thread spinlock support"
echocheck "spinlock support"
if cc_check $pthr
then
echores "yes"
Expand Down
10 changes: 10 additions & 0 deletions src/shogun/base/Parallel.h
Expand Up @@ -17,11 +17,21 @@

#ifdef HAVE_PTHREAD
#ifdef USE_SPINLOCKS
#ifdef DARWIN
#include <libkern/OSAtomic.h>

#define PTHREAD_LOCK_T OSSpinLock
#define PTHREAD_LOCK_INIT(lock) *lock = OS_SPINLOCK_INIT
#define PTHREAD_LOCK_DESTROY(lock)
#define PTHREAD_LOCK(lock) OSSpinLockLock(lock)
#define PTHREAD_UNLOCK(lock) OSSpinLockUnlock(lock)
#else
#define PTHREAD_LOCK_T pthread_spinlock_t
#define PTHREAD_LOCK_INIT(lock) pthread_spin_init(lock, 0)
#define PTHREAD_LOCK_DESTROY(lock) pthread_spin_destroy(lock)
#define PTHREAD_LOCK(lock) pthread_spin_lock(lock)
#define PTHREAD_UNLOCK(lock) pthread_spin_unlock(lock)
#endif
#else
#define PTHREAD_LOCK_T pthread_mutex_t
#define PTHREAD_LOCK_INIT(lock) pthread_mutex_init(lock, NULL)
Expand Down

0 comments on commit 5a10d5e

Please sign in to comment.