From: Greg Farnum Date: Wed, 14 Apr 2010 23:51:40 +0000 (-0700) Subject: atomic_t: Add a new version based on libatomic_ops. X-Git-Tag: v0.22~624^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ca74b4bb3d947958c8a22eaddca02193dfe77950;p=ceph.git atomic_t: Add a new version based on libatomic_ops. Hopefully this version will take less CPU since it isn't running Spinlocks, but we'll need to test for that. Includes appropriate Makefile and configure changes. --- diff --git a/configure.ac b/configure.ac index ee49113b3056..42114c92031a 100644 --- a/configure.ac +++ b/configure.ac @@ -96,6 +96,25 @@ AS_IF([test "x$with_hadoop" != xno], ])]) AM_CONDITIONAL(WITH_HADOOPCLIENT, [test "$HAVE_JNI" = "1"]) +#libatomic-ops? You want it! +AC_ARG_WITH([libatomic-ops], + [AS_HELP_STRING([--with-libatomic-ops], + [use libatomic-ops to build Ceph's atomic_t type])], + [], + [with_libatomic_ops=check]) +AS_IF([test "x$with_libatomic_ops" != xno], + [AC_CHECK_HEADER([atomic_ops.h], + [HAVE_ATOMIC_OPS=1], + [if test "x$with_libatomic_ops" != xcheck; then + AC_MSG_FAILURE( + [--with-libatomic-ops was given but atomic_ops.h not found]) + fi + ])]) +AS_IF([test "$HAVE_ATOMIC_OPS" = "1"], + AC_DEFINE([HAVE_ATOMIC_OPS], [1], [Defined if you have atomic_ops]), + AC_MSG_FAILURE([])) +AM_CONDITIONAL(WITH_LIBATOMIC, [test "$HAVE_ATOMIC_OPS" = "1"]) + # newsyn? requires mpi. #AC_ARG_WITH([newsyn], # [AS_HELP_STRING([--with-newsyn], [build newsyn target requires mpi])], diff --git a/src/Makefile.am b/src/Makefile.am index ddb65d0c9532..3c2dab401bb7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -246,10 +246,15 @@ BUILT_SOURCES += init-ceph mkcephfs INCLUDES = LDADD = + AM_CXXFLAGS = -Wall -D_FILE_OFFSET_BITS=64 -D_REENTRANT -D_THREAD_SAFE -rdynamic AM_CFLAGS = -Wall -D_FILE_OFFSET_BITS=64 -D_REENTRANT -D_THREAD_SAFE -rdynamic AM_LDFLAGS = +if WITH_LIBATOMIC +AM_LDFLAGS += -latomic_ops +endif + noinst_LIBRARIES = \ libcommon.a libcrush.a \ libmon.a libmds.a libosdc.a libosd.a libclient.a \ diff --git a/src/include/atomic.h b/src/include/atomic.h index 95a9f486d983..e9ebb17b9f31 100644 --- a/src/include/atomic.h +++ b/src/include/atomic.h @@ -19,6 +19,35 @@ # include "acconfig.h" #endif + +#ifdef HAVE_ATOMIC_OPS +//libatomic_ops implementation +#include +namespace ceph { + +class atomic_t { + AO_t val; +public: + atomic_t(AO_t i=0) : val(i) {} + void inc() { + AO_fetch_and_add1(&val); + } + AO_t dec() { + return AO_fetch_and_sub1_write(&val) - 1; + } + void add(AO_t add_me) { + AO_fetch_and_add(&val, add_me); + } + void sub(int sub_me) { + int sub = 0 - sub_me; + AO_fetch_and_add_write(&val, (AO_t)sub); + } + AO_t read() const { + return AO_load_full(&val); + } +}; +} +#else /* * crappy slow implementation that uses a pthreads spinlock. */ @@ -63,3 +92,4 @@ public: } #endif +#endif