AC_MSG_RESULT([no])
])
+#
+# Check for pthread spinlock (depends on ACX_PTHREAD)
+#
+saved_LIBS="$LIBS"
+saved_CFLAGS="$CFLAGS"
+LIBS="$PTHREAD_LIBS $LIBS"
+CFLAGS="$PTHREAD_CFLAGS $CFLAGS"
+AC_CHECK_FUNC([pthread_spin_init],
+ [AC_DEFINE(HAVE_PTHREAD_SPINLOCK, 1, [Define if you have pthread_spin_init])])
+LIBS="$saved_LIBS"
+CFLAGS="$saved_CFLAGS"
+
# Checks for typedefs, structures, and compiler characteristics.
#AC_HEADER_STDBOOL
#AC_C_CONST
#include <iostream>
#include <pthread.h>
+#include "include/Spinlock.h"
+
using ceph::HeartbeatMap;
class CephContextServiceThread : public Thread
_crypto_none(NULL),
_crypto_aes(NULL)
{
- pthread_spin_init(&_service_thread_lock, PTHREAD_PROCESS_SHARED);
+ ceph_spin_init(&_service_thread_lock);
_log = new ceph::log::Log(&_conf->subsys);
_log->start();
_log = NULL;
delete _conf;
- pthread_spin_destroy(&_service_thread_lock);
+ ceph_spin_destroy(&_service_thread_lock);
delete _crypto_none;
delete _crypto_aes;
void CephContext::start_service_thread()
{
- pthread_spin_lock(&_service_thread_lock);
+ ceph_spin_lock(&_service_thread_lock);
if (_service_thread) {
- pthread_spin_unlock(&_service_thread_lock);
+ ceph_spin_unlock(&_service_thread_lock);
return;
}
_service_thread = new CephContextServiceThread(this);
_service_thread->create();
- pthread_spin_unlock(&_service_thread_lock);
+ ceph_spin_unlock(&_service_thread_lock);
// make logs flush on_exit()
if (_conf->log_flush_on_exit)
void CephContext::reopen_logs()
{
- pthread_spin_lock(&_service_thread_lock);
+ ceph_spin_lock(&_service_thread_lock);
if (_service_thread)
_service_thread->reopen_logs();
- pthread_spin_unlock(&_service_thread_lock);
+ ceph_spin_unlock(&_service_thread_lock);
}
void CephContext::join_service_thread()
{
- pthread_spin_lock(&_service_thread_lock);
+ ceph_spin_lock(&_service_thread_lock);
CephContextServiceThread *thread = _service_thread;
if (!thread) {
- pthread_spin_unlock(&_service_thread_lock);
+ ceph_spin_unlock(&_service_thread_lock);
return;
}
_service_thread = NULL;
- pthread_spin_unlock(&_service_thread_lock);
+ ceph_spin_unlock(&_service_thread_lock);
thread->exit_thread();
thread->join();
#include "include/buffer.h"
#include "include/atomic.h"
#include "common/cmdparse.h"
+#include "include/Spinlock.h"
class AdminSocket;
class CephContextServiceThread;
AdminSocket *_admin_socket;
/* lock which protects service thread creation, destruction, etc. */
- pthread_spinlock_t _service_thread_lock;
+ ceph_spinlock_t _service_thread_lock;
/* The collection of profiling loggers associated with this context */
PerfCountersCollection *_perf_counters_collection;
#ifndef CEPH_SPINLOCK_H
#define CEPH_SPINLOCK_H
+#include "acconfig.h"
+
#include <pthread.h>
+typedef struct {
+#ifdef HAVE_PTHREAD_SPINLOCK
+ pthread_spinlock_t lock;
+#else
+ pthread_mutex_t lock;
+#endif
+} ceph_spinlock_t;
+
+#ifdef HAVE_PTHREAD_SPINLOCK
+
+static inline int ceph_spin_init(ceph_spinlock_t *l)
+{
+ return pthread_spin_init(&l->lock, PTHREAD_PROCESS_PRIVATE);
+}
+
+static inline int ceph_spin_destroy(ceph_spinlock_t *l)
+{
+ return pthread_spin_destroy(&l->lock);
+}
+
+static inline int ceph_spin_lock(ceph_spinlock_t *l)
+{
+ return pthread_spin_lock(&l->lock);
+}
+
+static inline int ceph_spin_unlock(ceph_spinlock_t *l)
+{
+ return pthread_spin_unlock(&l->lock);
+}
+
+#else /* !HAVE_PTHREAD_SPINLOCK */
+
+static inline int ceph_spin_init(ceph_spinlock_t *l)
+{
+ return pthread_mutex_init(&l->lock, NULL);
+}
+
+static inline int ceph_spin_destroy(ceph_spinlock_t *l)
+{
+ return pthread_mutex_destroy(&l->lock);
+}
+
+static inline int ceph_spin_lock(ceph_spinlock_t *l)
+{
+ return pthread_mutex_lock(&l->lock);
+}
+
+static inline int ceph_spin_unlock(ceph_spinlock_t *l)
+{
+ return pthread_mutex_unlock(&l->lock);
+}
+
+#endif
+
class Spinlock {
- mutable pthread_spinlock_t _lock;
+ mutable ceph_spinlock_t _lock;
public:
Spinlock() {
- pthread_spin_init(&_lock, PTHREAD_PROCESS_PRIVATE);
+ ceph_spin_init(&_lock);
}
~Spinlock() {
- pthread_spin_destroy(&_lock);
+ ceph_spin_destroy(&_lock);
}
// don't allow copying.
/// acquire spinlock
void lock() const {
- pthread_spin_lock(&_lock);
+ ceph_spin_lock(&_lock);
}
/// release spinlock
void unlock() const {
- pthread_spin_unlock(&_lock);
+ ceph_spin_unlock(&_lock);
}
class Locker {
/*
* crappy slow implementation that uses a pthreads spinlock.
*/
-#include <pthread.h>
-#include "include/assert.h"
+#include "include/Spinlock.h"
namespace ceph {
class atomic_t {
- mutable pthread_spinlock_t lock;
+ mutable ceph_spinlock_t lock;
signed long val;
public:
atomic_t(int i=0)
: val(i) {
- pthread_spin_init(&lock, PTHREAD_PROCESS_PRIVATE);
+ ceph_spin_init(&lock);
}
~atomic_t() {
- pthread_spin_destroy(&lock);
+ ceph_spin_destroy(&lock);
}
void set(size_t v) {
- pthread_spin_lock(&lock);
+ ceph_spin_lock(&lock);
val = v;
- pthread_spin_unlock(&lock);
+ ceph_spin_unlock(&lock);
}
int inc() {
- pthread_spin_lock(&lock);
+ ceph_spin_lock(&lock);
int r = ++val;
- pthread_spin_unlock(&lock);
+ ceph_spin_unlock(&lock);
return r;
}
int dec() {
- pthread_spin_lock(&lock);
+ ceph_spin_lock(&lock);
int r = --val;
- pthread_spin_unlock(&lock);
+ ceph_spin_unlock(&lock);
return r;
}
void add(int d) {
- pthread_spin_lock(&lock);
+ ceph_spin_lock(&lock);
val += d;
- pthread_spin_unlock(&lock);
+ ceph_spin_unlock(&lock);
}
void sub(int d) {
- pthread_spin_lock(&lock);
+ ceph_spin_lock(&lock);
val -= d;
- pthread_spin_unlock(&lock);
+ ceph_spin_unlock(&lock);
}
int read() const {
signed long ret;
- pthread_spin_lock(&lock);
+ ceph_spin_lock(&lock);
ret = val;
- pthread_spin_unlock(&lock);
+ ceph_spin_unlock(&lock);
return ret;
}
private:
#include "common/Timer.h"
#include "common/errno.h"
#include "auth/Crypto.h"
+#include "include/Spinlock.h"
#define dout_subsys ceph_subsys_ms
#undef dout_prefix
timeout(0),
local_connection(new Connection(this))
{
- pthread_spin_init(&global_seq_lock, PTHREAD_PROCESS_PRIVATE);
+ ceph_spin_init(&global_seq_lock);
init_local_connection();
}
#include "Pipe.h"
#include "Accepter.h"
+#include "include/Spinlock.h"
/*
* This class handles transmission and reception of messages. Generally
/// counter for the global seq our connection protocol uses
__u32 global_seq;
/// lock to protect the global_seq
- pthread_spinlock_t global_seq_lock;
+ ceph_spinlock_t global_seq_lock;
/**
* hash map of addresses to Pipes
* @return a global sequence ID that nobody else has seen.
*/
__u32 get_global_seq(__u32 old=0) {
- pthread_spin_lock(&global_seq_lock);
+ ceph_spin_lock(&global_seq_lock);
if (old > global_seq)
global_seq = old;
__u32 ret = ++global_seq;
- pthread_spin_unlock(&global_seq_lock);
+ ceph_spin_unlock(&global_seq_lock);
return ret;
}
/**