]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
atomic_t: Add a new version based on libatomic_ops.
authorGreg Farnum <gregf@hq.newdream.net>
Wed, 14 Apr 2010 23:51:40 +0000 (16:51 -0700)
committerGreg Farnum <gregf@hq.newdream.net>
Wed, 14 Apr 2010 23:54:48 +0000 (16:54 -0700)
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.

configure.ac
src/Makefile.am
src/include/atomic.h

index ee49113b3056dd6cd1fc7bc4a2d52faa6f6410ae..42114c92031aceef7815ef6dfe9e634b30178fa1 100644 (file)
@@ -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])],
index ddb65d0c9532f752f844ab359c21f7d1c3106567..3c2dab401bb77cb2127619d1e6600a699f0b4326 100644 (file)
@@ -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 \
index 95a9f486d9833c852db9a15a647b66c912f1221d..e9ebb17b9f317889aa057aa8299b8abcaee1ebef 100644 (file)
 # include "acconfig.h"
 #endif
 
+
+#ifdef HAVE_ATOMIC_OPS
+//libatomic_ops implementation
+#include <atomic_ops.h>
+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