Use a ./configure check to detect pthread spinlock availability
_POSIX_SPIN_LOCKS does not seem to be defined correctly on all systems (Debian libc 2.3.6). Fixes #262.
This commit is contained in:
@@ -414,6 +414,8 @@ dnl check if we can cancel threads
|
|||||||
AC_CHECK_FUNCS(pthread_cancel)
|
AC_CHECK_FUNCS(pthread_cancel)
|
||||||
dnl check if native rwlocks are available
|
dnl check if native rwlocks are available
|
||||||
AC_CHECK_FUNCS(pthread_rwlock_init)
|
AC_CHECK_FUNCS(pthread_rwlock_init)
|
||||||
|
dnl check if pthread spinlocks are available
|
||||||
|
AC_CHECK_FUNCS(pthread_spin_init)
|
||||||
dnl check if we have POSIX semaphore functions, including timed-wait
|
dnl check if we have POSIX semaphore functions, including timed-wait
|
||||||
AC_CHECK_FUNCS(sem_timedwait)
|
AC_CHECK_FUNCS(sem_timedwait)
|
||||||
LIBS=$saved_LIBS
|
LIBS=$saved_LIBS
|
||||||
|
|||||||
@@ -13,7 +13,6 @@
|
|||||||
* for more details.
|
* for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <unistd.h> /* for _POSIX_SPIN_LOCKS */
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
#include <library.h>
|
#include <library.h>
|
||||||
@@ -23,10 +22,6 @@
|
|||||||
#include "mutex.h"
|
#include "mutex.h"
|
||||||
#include "lock_profiler.h"
|
#include "lock_profiler.h"
|
||||||
|
|
||||||
#if defined(_POSIX_SPIN_LOCKS) && _POSIX_SPIN_LOCKS == -1
|
|
||||||
#undef _POSIX_SPIN_LOCKS
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct private_spinlock_t private_spinlock_t;
|
typedef struct private_spinlock_t private_spinlock_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -39,7 +34,7 @@ struct private_spinlock_t {
|
|||||||
*/
|
*/
|
||||||
spinlock_t public;
|
spinlock_t public;
|
||||||
|
|
||||||
#ifdef _POSIX_SPIN_LOCKS
|
#ifdef HAVE_PTHREAD_SPIN_INIT
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* wrapped pthread spin lock
|
* wrapped pthread spin lock
|
||||||
@@ -51,20 +46,20 @@ struct private_spinlock_t {
|
|||||||
*/
|
*/
|
||||||
lock_profile_t profile;
|
lock_profile_t profile;
|
||||||
|
|
||||||
#else /* _POSIX_SPIN_LOCKS */
|
#else /* HAVE_PTHREAD_SPIN_INIT */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* use a mutex if spin locks are not available
|
* use a mutex if spin locks are not available
|
||||||
*/
|
*/
|
||||||
mutex_t *mutex;
|
mutex_t *mutex;
|
||||||
|
|
||||||
#endif /* _POSIX_SPIN_LOCKS */
|
#endif /* HAVE_PTHREAD_SPIN_INIT */
|
||||||
};
|
};
|
||||||
|
|
||||||
METHOD(spinlock_t, lock, void,
|
METHOD(spinlock_t, lock, void,
|
||||||
private_spinlock_t *this)
|
private_spinlock_t *this)
|
||||||
{
|
{
|
||||||
#ifdef _POSIX_SPIN_LOCKS
|
#ifdef HAVE_PTHREAD_SPIN_INIT
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
profiler_start(&this->profile);
|
profiler_start(&this->profile);
|
||||||
@@ -82,7 +77,7 @@ METHOD(spinlock_t, lock, void,
|
|||||||
METHOD(spinlock_t, unlock, void,
|
METHOD(spinlock_t, unlock, void,
|
||||||
private_spinlock_t *this)
|
private_spinlock_t *this)
|
||||||
{
|
{
|
||||||
#ifdef _POSIX_SPIN_LOCKS
|
#ifdef HAVE_PTHREAD_SPIN_INIT
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
err = pthread_spin_unlock(&this->spinlock);
|
err = pthread_spin_unlock(&this->spinlock);
|
||||||
@@ -98,7 +93,7 @@ METHOD(spinlock_t, unlock, void,
|
|||||||
METHOD(spinlock_t, destroy, void,
|
METHOD(spinlock_t, destroy, void,
|
||||||
private_spinlock_t *this)
|
private_spinlock_t *this)
|
||||||
{
|
{
|
||||||
#ifdef _POSIX_SPIN_LOCKS
|
#ifdef HAVE_PTHREAD_SPIN_INIT
|
||||||
profiler_cleanup(&this->profile);
|
profiler_cleanup(&this->profile);
|
||||||
pthread_spin_destroy(&this->spinlock);
|
pthread_spin_destroy(&this->spinlock);
|
||||||
#else
|
#else
|
||||||
@@ -122,15 +117,12 @@ spinlock_t *spinlock_create()
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
#ifdef _POSIX_SPIN_LOCKS
|
#ifdef HAVE_PTHREAD_SPIN_INIT
|
||||||
pthread_spin_init(&this->spinlock, PTHREAD_PROCESS_PRIVATE);
|
pthread_spin_init(&this->spinlock, PTHREAD_PROCESS_PRIVATE);
|
||||||
profiler_init(&this->profile);
|
profiler_init(&this->profile);
|
||||||
#else
|
#else
|
||||||
#warning Using mutexes as spin lock alternatives
|
|
||||||
this->mutex = mutex_create(MUTEX_TYPE_DEFAULT);
|
this->mutex = mutex_create(MUTEX_TYPE_DEFAULT);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return &this->public;
|
return &this->public;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user