]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
test: migrate atomic_t to std::atomic<> 14655/head
authorJesse Williamson <jwilliamson@suse.de>
Thu, 27 Apr 2017 07:52:11 +0000 (00:52 -0700)
committerJesse Williamson <jwilliamson@suse.de>
Fri, 19 May 2017 15:25:37 +0000 (08:25 -0700)
Signed-off-by: Jesse Williamson <jwilliamson@suse.de>
20 files changed:
src/test/librados_test_stub/TestIoCtxImpl.cc
src/test/librados_test_stub/TestIoCtxImpl.h
src/test/librados_test_stub/TestRadosClient.cc
src/test/librados_test_stub/TestRadosClient.h
src/test/msgr/perf_msgr_client.cc
src/test/msgr/perf_msgr_server.cc
src/test/msgr/test_async_driver.cc
src/test/msgr/test_msgr.cc
src/test/objectstore/TestObjectStoreState.cc
src/test/objectstore/TestObjectStoreState.h
src/test/objectstore/workload_generator.cc
src/test/objectstore/workload_generator.h
src/test/osdc/FakeWriteback.cc
src/test/osdc/FakeWriteback.h
src/test/osdc/MemWriteback.cc
src/test/osdc/MemWriteback.h
src/test/osdc/object_cacher_stress.cc
src/test/perf_local.cc
src/test/system/systest_runnable.cc
src/test/test_stress_watch.cc

index 5200bea84bbe2450831598c8c3d013408cba77eb..d5de8b54aa6c2588cdbea9611da3696253274dd7 100644 (file)
@@ -39,15 +39,15 @@ TestIoCtxImpl::TestIoCtxImpl(const TestIoCtxImpl& rhs)
 }
 
 TestIoCtxImpl::~TestIoCtxImpl() {
-  assert(m_pending_ops.read() == 0);
+  assert(m_pending_ops == 0);
 }
 
 void TestObjectOperationImpl::get() {
-  m_refcount.inc();
+  m_refcount++;
 }
 
 void TestObjectOperationImpl::put() {
-  if (m_refcount.dec() == 0) {
+  if (--m_refcount == 0) {
     ANNOTATE_HAPPENS_AFTER(&m_refcount);
     ANNOTATE_HAPPENS_BEFORE_FORGET_ALL(&m_refcount);
     delete this;
@@ -57,11 +57,11 @@ void TestObjectOperationImpl::put() {
 }
 
 void TestIoCtxImpl::get() {
-  m_refcount.inc();
+  m_refcount++;
 }
 
 void TestIoCtxImpl::put() {
-  if (m_refcount.dec() == 0) {
+  if (--m_refcount == 0) {
     m_client->put();
     delete this;
   }
@@ -95,7 +95,7 @@ void TestIoCtxImpl::aio_flush_async(AioCompletionImpl *c) {
 void TestIoCtxImpl::aio_notify(const std::string& oid, AioCompletionImpl *c,
                                bufferlist& bl, uint64_t timeout_ms,
                                bufferlist *pbl) {
-  m_pending_ops.inc();
+  m_pending_ops++;
   c->get();
   C_AioNotify *ctx = new C_AioNotify(this, c);
   m_client->get_watch_notify()->aio_notify(m_client, oid, bl, timeout_ms, pbl,
@@ -107,7 +107,7 @@ int TestIoCtxImpl::aio_operate(const std::string& oid, TestObjectOperationImpl &
                                int flags) {
   // TODO flags for now
   ops.get();
-  m_pending_ops.inc();
+  m_pending_ops++;
   m_client->add_aio_operation(oid, true, boost::bind(
     &TestIoCtxImpl::execute_aio_operations, this, oid, &ops,
     reinterpret_cast<bufferlist*>(0),
@@ -121,7 +121,7 @@ int TestIoCtxImpl::aio_operate_read(const std::string& oid,
                                     bufferlist *pbl) {
   // TODO ignoring flags for now
   ops.get();
-  m_pending_ops.inc();
+  m_pending_ops++;
   m_client->add_aio_operation(oid, true, boost::bind(
     &TestIoCtxImpl::execute_aio_operations, this, oid, &ops, pbl, m_snapc), c);
   return 0;
@@ -129,7 +129,7 @@ int TestIoCtxImpl::aio_operate_read(const std::string& oid,
 
 int TestIoCtxImpl::aio_watch(const std::string& o, AioCompletionImpl *c,
                              uint64_t *handle, librados::WatchCtx2 *watch_ctx) {
-  m_pending_ops.inc();
+  m_pending_ops++;
   c->get();
   C_AioNotify *ctx = new C_AioNotify(this, c);
   if (m_client->is_blacklisted()) {
@@ -142,7 +142,7 @@ int TestIoCtxImpl::aio_watch(const std::string& o, AioCompletionImpl *c,
 }
 
 int TestIoCtxImpl::aio_unwatch(uint64_t handle, AioCompletionImpl *c) {
-  m_pending_ops.inc();
+  m_pending_ops++;
   c->get();
   C_AioNotify *ctx = new C_AioNotify(this, c);
   if (m_client->is_blacklisted()) {
@@ -198,7 +198,7 @@ int TestIoCtxImpl::operate(const std::string& oid, TestObjectOperationImpl &ops)
   AioCompletionImpl *comp = new AioCompletionImpl();
 
   ops.get();
-  m_pending_ops.inc();
+  m_pending_ops++;
   m_client->add_aio_operation(oid, false, boost::bind(
     &TestIoCtxImpl::execute_aio_operations, this, oid, &ops,
     reinterpret_cast<bufferlist*>(0), m_snapc), comp);
@@ -214,7 +214,7 @@ int TestIoCtxImpl::operate_read(const std::string& oid, TestObjectOperationImpl
   AioCompletionImpl *comp = new AioCompletionImpl();
 
   ops.get();
-  m_pending_ops.inc();
+  m_pending_ops++;
   m_client->add_aio_operation(oid, false, boost::bind(
     &TestIoCtxImpl::execute_aio_operations, this, oid, &ops, pbl,
     m_snapc), comp);
@@ -361,13 +361,13 @@ int TestIoCtxImpl::execute_aio_operations(const std::string& oid,
       }
     }
   }
-  m_pending_ops.dec();
+  m_pending_ops--;
   ops->put();
   return ret;
 }
 
 void TestIoCtxImpl::handle_aio_notify_complete(AioCompletionImpl *c, int r) {
-  m_pending_ops.dec();
+  m_pending_ops--;
 
   m_client->finish_aio_completion(c, r);
 }
index aa5318e1171d253716a369478ca71c85fcc6f046..04629d128ff0c6206a6c38724db47ad4bcdeef15 100644 (file)
@@ -4,12 +4,14 @@
 #ifndef CEPH_TEST_IO_CTX_IMPL_H
 #define CEPH_TEST_IO_CTX_IMPL_H
 
+#include <list>
+#include <atomic>
+
+#include <boost/function.hpp>
+
 #include "include/rados/librados.hpp"
-#include "include/atomic.h"
 #include "include/Context.h"
 #include "common/snap_types.h"
-#include <boost/function.hpp>
-#include <list>
 
 namespace librados {
 
@@ -30,7 +32,7 @@ public:
 
   ObjectOperations ops;
 private:
-  atomic_t m_refcount;
+  std::atomic<uint64_t> m_refcount = { 0 };
 };
 
 class TestIoCtxImpl {
@@ -179,8 +181,8 @@ private:
   std::string m_pool_name;
   snap_t m_snap_seq;
   SnapContext m_snapc;
-  atomic_t m_refcount;
-  atomic_t m_pending_ops;
+  std::atomic<uint64_t> m_refcount = { 0 };
+  std::atomic<uint64_t> m_pending_ops = { 0 };
 
   void handle_aio_notify_complete(AioCompletionImpl *aio_comp, int r);
 };
index 156bd15ec9a53e1ea2018a2cb26fdbeeb707a2cf..546973558d2bc8b88ecfa5642506ee3d7499bad0 100644 (file)
@@ -11,6 +11,8 @@
 #include <boost/thread.hpp>
 #include <errno.h>
 
+#include <atomic>
+
 static int get_concurrency() {
   int concurrency = 0;
   char *env = getenv("LIBRADOS_CONCURRENCY");
@@ -114,11 +116,11 @@ TestRadosClient::~TestRadosClient() {
 }
 
 void TestRadosClient::get() {
-  m_refcount.inc();
+  m_refcount++;
 }
 
 void TestRadosClient::put() {
-  if (m_refcount.dec() == 0) {
+  if (--m_refcount == 0) {
     shutdown();
     delete this;
   }
@@ -180,7 +182,7 @@ void TestRadosClient::add_aio_operation(const std::string& oid,
 
 struct WaitForFlush {
   int flushed() {
-    if (count.dec() == 0) {
+    if (--count == 0) {
       aio_finisher->queue(new FunctionContext(boost::bind(
         &finish_aio_completion, c, 0)));
       delete this;
@@ -188,7 +190,7 @@ struct WaitForFlush {
     return 0;
   }
 
-  atomic_t count;
+  std::atomic<int64_t> count = { 0 };
   Finisher *aio_finisher;
   AioCompletionImpl *c;
 };
@@ -204,7 +206,7 @@ void TestRadosClient::flush_aio_operations(AioCompletionImpl *c) {
   c->get();
 
   WaitForFlush *wait_for_flush = new WaitForFlush();
-  wait_for_flush->count.set(m_finishers.size());
+  wait_for_flush->count = m_finishers.size();
   wait_for_flush->aio_finisher = m_aio_finisher;
   wait_for_flush->c = c;
 
index 1f14172ca3d6f4b06964a39f4e0e877a7581cf0d..7e84916bc754d6ad4f2cea7e1112f2c2c0cbb52b 100644 (file)
@@ -4,17 +4,19 @@
 #ifndef CEPH_TEST_RADOS_CLIENT_H
 #define CEPH_TEST_RADOS_CLIENT_H
 
+#include <map>
+#include <list>
+#include <string>
+#include <vector>
+#include <atomic>
+
+#include <boost/function.hpp>
+#include <boost/functional/hash.hpp>
+
 #include "include/rados/librados.hpp"
 #include "common/config.h"
-#include "include/atomic.h"
 #include "include/buffer_fwd.h"
 #include "test/librados_test_stub/TestWatchNotify.h"
-#include <boost/function.hpp>
-#include <boost/functional/hash.hpp>
-#include <list>
-#include <map>
-#include <string>
-#include <vector>
 
 class Finisher;
 
@@ -113,7 +115,7 @@ protected:
 private:
 
   CephContext *m_cct;
-  atomic_t m_refcount;
+  std::atomic<uint64_t> m_refcount = { 0 };
 
   TestWatchNotify *m_watch_notify;
 
index 5bb20715c1a5735cc7e2a03591917dc56b23c9f5..d8d25720033f7b1804b41013e19affc26db656b3 100644 (file)
@@ -22,7 +22,6 @@
 
 using namespace std;
 
-#include "include/atomic.h"
 #include "common/ceph_argparse.h"
 #include "common/debug.h"
 #include "common/Cycles.h"
@@ -30,6 +29,8 @@ using namespace std;
 #include "msg/Messenger.h"
 #include "messages/MOSDOp.h"
 
+#include <atomic>
+
 class MessengerClient {
   class ClientThread;
   class ClientDispatcher : public Dispatcher {
@@ -67,7 +68,7 @@ class MessengerClient {
     Messenger *msgr;
     int concurrent;
     ConnectionRef conn;
-    atomic_t client_inc;
+    std::atomic<unsigned> client_inc = { 0 };
     object_t oid;
     object_locator_t oloc;
     pg_t pgid;
@@ -82,7 +83,7 @@ class MessengerClient {
     uint64_t inflight;
 
     ClientThread(Messenger *m, int c, ConnectionRef con, int len, int ops, int think_time_us):
-        msgr(m), concurrent(c), conn(con), client_inc(0), oid("object-name"), oloc(1, 1), msg_len(len), ops(ops),
+        msgr(m), concurrent(c), conn(con), oid("object-name"), oloc(1, 1), msg_len(len), ops(ops),
         dispatcher(think_time_us, this), lock("MessengerBenchmark::ClientThread::lock") {
       m->add_dispatcher_head(&dispatcher);
       bufferptr ptr(msg_len);
@@ -98,7 +99,7 @@ class MessengerClient {
        hobject_t hobj(oid, oloc.key, CEPH_NOSNAP, pgid.ps(), pgid.pool(),
                       oloc.nspace);
        spg_t spgid(pgid);
-        MOSDOp *m = new MOSDOp(client_inc.read(), 0, hobj, spgid, 0, 0, 0);
+        MOSDOp *m = new MOSDOp(client_inc, 0, hobj, spgid, 0, 0, 0);
         m->write(0, msg_len, data);
         inflight++;
         conn->send_message(m);
index c687d77a64932d9b28acafce3cbc4a7a66e3b76f..79e36721aa843f3e9659b13555a6c6cf789ac00c 100644 (file)
@@ -22,7 +22,6 @@
 
 using namespace std;
 
-#include "include/atomic.h"
 #include "common/ceph_argparse.h"
 #include "common/debug.h"
 #include "global/global_init.h"
index a93cffa0f4e2978ee26943ffd4a2ba054e29f88a..e68e57b6ba83e428883883da10cca4b9d8e1dbbc 100644 (file)
 #include <stdint.h>
 #include <arpa/inet.h>
 #include "include/Context.h"
-#include "include/atomic.h"
 #include "common/Mutex.h"
 #include "common/Cond.h"
 #include "global/global_init.h"
 #include "common/ceph_argparse.h"
 #include "msg/async/Event.h"
 
+#include <atomic>
+
 // We use epoll, kqueue, evport, select in descending order by performance.
 #if defined(__linux__)
 #define HAVE_EPOLL 1
@@ -293,15 +294,15 @@ class Worker : public Thread {
 };
 
 class CountEvent: public EventCallback {
-  atomic_t *count;
+  std::atomic<unsigned> *count;
   Mutex *lock;
   Cond *cond;
 
  public:
-  CountEvent(atomic_t *atomic, Mutex *l, Cond *c): count(atomic), lock(l), cond(c) {}
+  CountEvent(std::atomic<unsigned> *atomic, Mutex *l, Cond *c): count(atomic), lock(l), cond(c) {}
   void do_request(int id) override {
     lock->Lock();
-    count->dec();
+    (*count)--;
     cond->Signal();
     lock->Unlock();
   }
@@ -309,18 +310,18 @@ class CountEvent: public EventCallback {
 
 TEST(EventCenterTest, DispatchTest) {
   Worker worker1(g_ceph_context, 1), worker2(g_ceph_context, 2);
-  atomic_t count(0);
+  std::atomic<unsigned> count = { 0 };
   Mutex lock("DispatchTest::lock");
   Cond cond;
   worker1.create("worker_1");
   worker2.create("worker_2");
   for (int i = 0; i < 10000; ++i) {
-    count.inc();
+    count++;
     worker1.center.dispatch_event_external(EventCallbackRef(new CountEvent(&count, &lock, &cond)));
-    count.inc();
+    count++;
     worker2.center.dispatch_event_external(EventCallbackRef(new CountEvent(&count, &lock, &cond)));
     Mutex::Locker l(lock);
-    while (count.read())
+    while (count)
       cond.Wait(lock);
   }
   worker1.stop();
index 518ec7732ee2b2732bb99b82379f4f726e20ce82..831f71aa85e54267edb8a1586f1f60b044420d9c 100644 (file)
@@ -1370,9 +1370,9 @@ class MarkdownDispatcher : public Dispatcher {
   set<ConnectionRef> conns;
   bool last_mark;
  public:
-  atomic_t count;
+  std::atomic<int64_t> count = { 0 };
   explicit MarkdownDispatcher(bool s): Dispatcher(g_ceph_context), lock("MarkdownDispatcher::lock"),
-                              last_mark(false), count(0) {}
+                              last_mark(false) {}
   bool ms_can_fast_dispatch_any() const override { return false; }
   bool ms_can_fast_dispatch(const Message *m) const override {
     switch (m->get_type()) {
@@ -1395,7 +1395,7 @@ class MarkdownDispatcher : public Dispatcher {
   bool ms_dispatch(Message *m) override {
     lderr(g_ceph_context) << __func__ << " conn: " << m->get_connection() << dendl;
     Mutex::Locker l(lock);
-    count.inc();
+    count++;
     conns.insert(m->get_connection());
     if (conns.size() < 2 && !last_mark) {
       m->put();
@@ -1471,8 +1471,8 @@ TEST_P(MessengerTest, MarkdownTest) {
     ASSERT_EQ(conn1->send_message(m), 0);
     m = new MPing();
     ASSERT_EQ(conn2->send_message(m), 0);
-    CHECK_AND_WAIT_TRUE(srv_dispatcher.count.read() > last + 1);
-    if (srv_dispatcher.count.read() == last) {
+    CHECK_AND_WAIT_TRUE(srv_dispatcher.count > last + 1);
+    if (srv_dispatcher.count == last) {
       lderr(g_ceph_context) << __func__ << " last is " << last << dendl;
       equal = true;
       equal_count++;
@@ -1480,7 +1480,7 @@ TEST_P(MessengerTest, MarkdownTest) {
       equal = false;
       equal_count = 0;
     }
-    last = srv_dispatcher.count.read();
+    last = srv_dispatcher.count;
     if (equal_count)
       usleep(1000*500);
     ASSERT_FALSE(equal && equal_count > 3);
index 9a4f6e1be949d6bd8c1959b45c2f9d52d88d4586..7eab8b3842ffa7718e25f6902f226cbd4a035638 100644 (file)
@@ -77,7 +77,7 @@ void TestObjectStoreState::init(int colls, int objs)
     m_collections_ids.push_back(coll_id);
     m_next_coll_nr++;
   }
-  dout(5) << "init has " << m_in_flight.read() << "in-flight transactions" << dendl;
+  dout(5) << "init has " << m_in_flight.load() << "in-flight transactions" << dendl;
   wait_for_done();
   dout(5) << "init finished" << dendl;
 }
index c59d4769113ee76243b763542a1d1601d4ddf88d..7d1ac8c082135a402a3480d2ea75792623ada58c 100644 (file)
@@ -65,19 +65,19 @@ public:
   int m_num_objects;
 
   int m_max_in_flight;
-  atomic_t m_in_flight;
+  std::atomic<int> m_in_flight = { 0 };
   Mutex m_finished_lock;
   Cond m_finished_cond;
 
   void wait_for_ready() {
     Mutex::Locker locker(m_finished_lock);
-    while ((m_max_in_flight > 0) && ((int)m_in_flight.read() >= m_max_in_flight))
+    while ((m_max_in_flight > 0) && (m_in_flight >= m_max_in_flight))
       m_finished_cond.Wait(m_finished_lock);
   }
 
   void wait_for_done() {
     Mutex::Locker locker(m_finished_lock);
-    while (m_in_flight.read())
+    while (m_in_flight)
       m_finished_cond.Wait(m_finished_lock);
   }
 
@@ -101,7 +101,6 @@ public:
   explicit TestObjectStoreState(ObjectStore *store) :
     m_next_coll_nr(0), m_num_objs_per_coll(10), m_num_objects(0),
     m_max_in_flight(0), m_finished_lock("Finished Lock"), m_next_pool(1) {
-    m_in_flight.set(0);
     m_store.reset(store);
   }
   ~TestObjectStoreState() { 
@@ -119,11 +118,11 @@ public:
   }
 
   int inc_in_flight() {
-    return ((int) m_in_flight.inc());
+    return ++m_in_flight;
   }
 
   int dec_in_flight() {
-    return ((int) m_in_flight.dec());
+    return --m_in_flight;
   }
 
   coll_entry_t *coll_create(int id);
index a529e576b7909a512445f2d940f0d9066c0cf216..343cc2cd7362ca8f67b6035c9b8ea3f92374e040 100644 (file)
@@ -60,7 +60,7 @@ WorkloadGenerator::WorkloadGenerator(vector<const char*> args)
 {
   int err = 0;
 
-  m_nr_runs.set(0);
+  m_nr_runs = 0;
 
   init_args(args);
   dout(0) << "data            = " << g_conf->osd_data << dendl;
@@ -352,7 +352,7 @@ void WorkloadGenerator::do_destroy_collection(ObjectStore::Transaction *t,
                                              coll_entry_t *entry,
                                              C_StatState *stat)
 {  
-  m_nr_runs.set(0);
+  m_nr_runs = 0;
   entry->m_osr.flush();
   vector<ghobject_t> ls;
   m_store->collection_list(entry->m_coll, ghobject_t(), ghobject_t::get_max(),
@@ -431,7 +431,7 @@ void WorkloadGenerator::run()
 
     dout(5) << __func__
         << " m_finished_lock is-locked: " << m_finished_lock.is_locked()
-        << " in-flight: " << m_in_flight.read()
+        << " in-flight: " << m_in_flight.load()
         << dendl;
 
     wait_for_ready();
@@ -502,7 +502,7 @@ queue_tx:
   } while (true);
 
   dout(2) << __func__ << " waiting for "
-         << m_in_flight.read() << " in-flight transactions" << dendl;
+         << m_in_flight.load() << " in-flight transactions" << dendl;
 
   wait_for_done();
 
index 978cd043b1ec2d34ad9ae3c3d2d4c22ff1bdf303..a1c21b9d0718d09c19a531d128883bc07cd36bd1 100644 (file)
 #include <boost/scoped_ptr.hpp>
 #include <boost/random/mersenne_twister.hpp>
 #include <boost/random/uniform_int.hpp>
-#include <map>
 #include <sys/time.h>
 
 #include "TestObjectStoreState.h"
 
+#include <map>
+#include <atomic>
+
 typedef boost::mt11213b rngen_t;
 
 class WorkloadGenerator : public TestObjectStoreState {
@@ -57,7 +59,7 @@ class WorkloadGenerator : public TestObjectStoreState {
   int m_max_in_flight;
   int m_num_ops;
   int m_destroy_coll_every_nr_runs;
-  atomic_t m_nr_runs;
+  std::atomic<int> m_nr_runs = { 0 };
 
   int m_num_colls;
 
@@ -110,7 +112,7 @@ class WorkloadGenerator : public TestObjectStoreState {
 
   bool should_destroy_collection() {
     return ((m_destroy_coll_every_nr_runs > 0) &&
-        ((int)m_nr_runs.read() >= m_destroy_coll_every_nr_runs));
+        (m_nr_runs >= m_destroy_coll_every_nr_runs));
   }
   void do_destroy_collection(ObjectStore::Transaction *t, coll_entry_t *entry,
       C_StatState *stat);
@@ -135,7 +137,7 @@ public:
     void finish(int r) override
     {
       TestObjectStoreState::C_OnFinished::finish(r);
-      wrkldgen_state->m_nr_runs.inc();
+      wrkldgen_state->m_nr_runs++;
     }
   };
 
index 72e80e433f6d79cf00daaadd260b132f29942c14..24a780288b3ae8629af8d3e0518e2425ea3735b3 100644 (file)
@@ -84,7 +84,7 @@ ceph_tid_t FakeWriteback::write(const object_t& oid,
   C_Delay *wrapper = new C_Delay(m_cct, oncommit, m_lock, off, NULL,
                                 m_delay_ns);
   m_finisher->queue(wrapper, 0);
-  return m_tid.inc();
+  return ++m_tid;
 }
 
 bool FakeWriteback::may_copy_on_write(const object_t&, uint64_t, uint64_t,
index 6112eb7208262c28c32ef0cfee9fea87d4b1733b..0d3705c87fd58e1b56ba557943f6e343cb0c00b3 100644 (file)
@@ -3,12 +3,13 @@
 #ifndef CEPH_TEST_OSDC_FAKEWRITEBACK_H
 #define CEPH_TEST_OSDC_FAKEWRITEBACK_H
 
-#include "include/atomic.h"
 #include "include/Context.h"
 #include "include/types.h"
 #include "osd/osd_types.h"
 #include "osdc/WritebackHandler.h"
 
+#include <atomic>
+
 class Finisher;
 class Mutex;
 
@@ -40,7 +41,7 @@ private:
   CephContext *m_cct;
   Mutex *m_lock;
   uint64_t m_delay_ns;
-  atomic_t m_tid;
+  std::atomic<unsigned> m_tid = { 0 };
   Finisher *m_finisher;
 };
 
index e9e1f9fe345baaaa4f3761bd244aea1a98969e27..f8f9844b30c780a94adab8835b2c75f30108ee5b 100644 (file)
@@ -116,7 +116,7 @@ ceph_tid_t MemWriteback::write(const object_t& oid,
   C_DelayWrite *wrapper = new C_DelayWrite(this, m_cct, oncommit, m_lock, oid,
                                           off, len, bl, m_delay_ns);
   m_finisher->queue(wrapper, 0);
-  return m_tid.inc();
+  return ++m_tid;
 }
 
 void MemWriteback::write_object_data(const object_t& oid, uint64_t off, uint64_t len,
index a073cbf1760dfdbc6e70cd63ba085e8378f31171..84ea78f5a2c4e34876f2dbf907d0957f32cac116 100644 (file)
@@ -3,12 +3,13 @@
 #ifndef CEPH_TEST_OSDC_MEMWRITEBACK_H
 #define CEPH_TEST_OSDC_MEMWRITEBACK_H
 
-#include "include/atomic.h"
 #include "include/Context.h"
 #include "include/types.h"
 #include "osd/osd_types.h"
 #include "osdc/WritebackHandler.h"
 
+#include <atomic>
+
 class Finisher;
 class Mutex;
 
@@ -45,7 +46,7 @@ private:
   CephContext *m_cct;
   Mutex *m_lock;
   uint64_t m_delay_ns;
-  atomic_t m_tid;
+  std::atomic<unsigned> m_tid = { 0 };
   Finisher *m_finisher;
 };
 
index c23c6c26ed33de26c9ff8c371c06c1b39a4f0562..fc9c56f955548b09cdd33a40331a672fa1ff3f39 100644 (file)
@@ -14,7 +14,6 @@
 #include "common/Mutex.h"
 #include "common/snap_types.h"
 #include "global/global_init.h"
-#include "include/atomic.h"
 #include "include/buffer.h"
 #include "include/Context.h"
 #include "include/stringify.h"
@@ -23,6 +22,8 @@
 #include "FakeWriteback.h"
 #include "MemWriteback.h"
 
+#include <atomic>
+
 // XXX: Only tests default namespace
 struct op_data {
   op_data(std::string oid, uint64_t offset, uint64_t len, bool read)
@@ -35,19 +36,19 @@ struct op_data {
   ObjectExtent extent;
   bool is_read;
   ceph::bufferlist result;
-  atomic_t done;
+  std::atomic<unsigned> done = { 0 };
 };
 
 class C_Count : public Context {
   op_data *m_op;
-  atomic_t *m_outstanding;
+  std::atomic<unsigned> *m_outstanding = nullptr;
 public:
-  C_Count(op_data *op, atomic_t *outstanding)
+  C_Count(op_data *op, std::atomic<unsigned> *outstanding)
     : m_op(op), m_outstanding(outstanding) {}
   void finish(int r) override {
-    m_op->done.inc();
-    assert(m_outstanding->read() > 0);
-    m_outstanding->dec();
+    m_op->done++;
+    assert(m_outstanding > 0);
+    *m_outstanding--;
   }
 };
 
@@ -67,7 +68,7 @@ int stress_test(uint64_t num_ops, uint64_t num_objs,
                   true);
   obc.start();
 
-  atomic_t outstanding_reads;
+  std::atomic<unsigned> outstanding_reads = { 0 };
   vector<ceph::shared_ptr<op_data> > ops;
   ObjectCacher::ObjectSet object_set(NULL, 0, 0);
   SnapContext snapc;
@@ -100,7 +101,7 @@ int stress_test(uint64_t num_ops, uint64_t num_objs,
     if (op->is_read) {
       ObjectCacher::OSDRead *rd = obc.prepare_read(CEPH_NOSNAP, &op->result, 0);
       rd->extents.push_back(op->extent);
-      outstanding_reads.inc();
+      outstanding_reads++;
       Context *completion = new C_Count(op.get(), &outstanding_reads);
       lock.Lock();
       int r = obc.readx(rd, &object_set, completion);
@@ -128,7 +129,7 @@ int stress_test(uint64_t num_ops, uint64_t num_objs,
     std::cout << "waiting for read " << i << ops[i]->extent << std::endl;
     uint64_t done = 0;
     while (done == 0) {
-      done = ops[i]->done.read();
+      done = ops[i]->done;
       if (!done) {
        usleep(500);
       }
index a74ef8342adb8f6042950ea97268229bcac63cee..98cccd87bbd58a013bfb472807dacd74acec51ad 100644 (file)
@@ -41,7 +41,6 @@
 #include <xmmintrin.h>
 #endif
 
-#include "include/atomic.h"
 #include "include/buffer.h"
 #include "include/encoding.h"
 #include "include/ceph_hash.h"
@@ -57,6 +56,8 @@
 
 #include "test/perf_helper.h"
 
+#include <atomic>
+
 using namespace ceph;
 
 /**
@@ -95,15 +96,15 @@ void discard(void* value) {
 // Test functions start here
 //----------------------------------------------------------------------
 
-// Measure the cost of atomic_t::compare_and_swap
+// Measure the cost of atomic compare-and-swap
 double atomic_int_cmp()
 {
   int count = 1000000;
-  atomic_t value(11);
-  int test = 11;
+  std::atomic<unsigned> value = { 11 };
+  unsigned int test = 11;
   uint64_t start = Cycles::rdtsc();
   for (int i = 0; i < count; i++) {
-    value.compare_and_swap(test, test+2);
+    value.compare_exchange_strong(test, test+2);
     test += 2;
   }
   uint64_t stop = Cycles::rdtsc();
@@ -111,43 +112,43 @@ double atomic_int_cmp()
   return Cycles::to_seconds(stop - start)/count;
 }
 
-// Measure the cost of atomic_t::inc
+// Measure the cost of incrementing an atomic
 double atomic_int_inc()
 {
   int count = 1000000;
-  atomic_t value(11);
+  std::atomic<int64_t> value = { 11 };
   uint64_t start = Cycles::rdtsc();
   for (int i = 0; i < count; i++) {
-    value.inc();
+    value++;
   }
   uint64_t stop = Cycles::rdtsc();
   // printf("Final value: %d\n", value.load());
   return Cycles::to_seconds(stop - start)/count;
 }
 
-// Measure the cost of reading an atomic_t
+// Measure the cost of reading an atomic
 double atomic_int_read()
 {
   int count = 1000000;
-  atomic_t value(11);
+  std::atomic<int64_t> value = { 11 };
   int total = 0;
   uint64_t start = Cycles::rdtsc();
   for (int i = 0; i < count; i++) {
-    total += value.read();
+    total += value;
   }
   uint64_t stop = Cycles::rdtsc();
   // printf("Total: %d\n", total);
   return Cycles::to_seconds(stop - start)/count;
 }
 
-// Measure the cost of storing a new value in a atomic_t
+// Measure the cost of storing a new value in an atomic
 double atomic_int_set()
 {
   int count = 1000000;
-  atomic_t value(11);
+  std::atomic<int64_t> value = { 11 };
   uint64_t start = Cycles::rdtsc();
   for (int i = 0; i < count; i++) {
-    value.set(88);
+    value = 88;
   }
   uint64_t stop = Cycles::rdtsc();
   return Cycles::to_seconds(stop - start)/count;
@@ -483,12 +484,12 @@ class CenterWorker : public Thread {
 };
 
 class CountEvent: public EventCallback {
-  atomic_t *count;
+  std::atomic<int64_t> *count;
 
  public:
-  explicit CountEvent(atomic_t *atomic): count(atomic) {}
+  explicit CountEvent(std::atomic<int64_t> *atomic): count(atomic) {}
   void do_request(int id) override {
-    count->dec();
+    (*count)--;
   }
 };
 
@@ -497,20 +498,20 @@ double eventcenter_dispatch()
   int count = 100000;
 
   CenterWorker worker(g_ceph_context);
-  atomic_t flag(1);
+  std::atomic<int64_t> flag = { 1 };
   worker.create("evt_center_disp");
   EventCallbackRef count_event(new CountEvent(&flag));
 
   worker.center.dispatch_event_external(count_event);
   // Start a new thread and wait for it to ready.
-  while (flag.read())
+  while (flag)
     usleep(100);
 
   uint64_t start = Cycles::rdtsc();
   for (int i = 0; i < count; i++) {
-    flag.set(1);
+    flag = 1;
     worker.center.dispatch_event_external(count_event);
-    while (flag.read())
+    while (flag)
       ;
   }
   uint64_t stop = Cycles::rdtsc();
index 95453391207a549d308772fc2a4296d4dc17133e..7a97f2ffbba4ea7778f5ae65d2afd893fd016c2d 100644 (file)
@@ -14,7 +14,6 @@
 
 #include "include/compat.h"
 #include "common/errno.h"
-#include "include/atomic.h"
 #include "systest_runnable.h"
 #include "systest_settings.h"
 
@@ -31,6 +30,7 @@
 #include <sys/wait.h>
 #include <unistd.h>
 #include <vector>
+#include <atomic>
 
 using std::ostringstream;
 using std::string;
@@ -44,7 +44,7 @@ static pid_t do_gettid(void)
 #endif
 }
 
-ceph::atomic_t m_highest_id(0);
+std::atomic<unsigned> m_highest_id = { 0 };
 
 SysTestRunnable::
 SysTestRunnable(int argc, const char **argv)
@@ -53,7 +53,7 @@ SysTestRunnable(int argc, const char **argv)
     m_argv_orig(NULL)
 {
   m_started = false;
-  m_id = m_highest_id.inc();
+  m_id = ++m_highest_id;
   memset(&m_pthread, 0, sizeof(m_pthread));
   update_id_str(false);
   set_argv(argc, argv);
index ff964df17ed30ff20e944bc523bd8811765ce82d..8604328b59c2bd49b56c58f0323de6f6a9e9ed1e 100644 (file)
@@ -1,6 +1,5 @@
 #include "include/rados/librados.h"
 #include "include/rados/librados.hpp"
-#include "include/atomic.h"
 #include "include/utime.h"
 #include "common/Thread.h"
 #include "common/Clock.h"
@@ -13,6 +12,7 @@
 #include <sstream>
 #include <iostream>
 #include <string>
+#include <atomic>
 
 #include "test/librados/TestCase.h"
 
@@ -23,7 +23,7 @@ using std::ostringstream;
 using std::string;
 
 static sem_t *sem;
-static atomic_t stop_flag;
+static std::atomic<bool> stop_flag = { false };
 
 class WatchNotifyTestCtx : public WatchCtx
 {
@@ -45,7 +45,7 @@ struct WatcherUnwatcher : public Thread {
   void *entry() override {
     Rados cluster;
     connect_cluster_pp(cluster);
-    while (!stop_flag.read()) {
+    while (!stop_flag) {
       IoCtx ioctx;
       cluster.ioctx_create(pool.c_str(), ioctx);
 
@@ -113,7 +113,7 @@ TEST_P(WatchStress, Stress1) {
     ioctx.unwatch("foo", handle);
     ioctx.close();
   }
-  stop_flag.set(1);
+  stop_flag = true;
   thr->join();
   nioctx.close();
   ASSERT_EQ(0, destroy_one_pool_pp(pool_name, ncluster));