]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
tools (rbd*): migrate atomic_t to std::atomic<>
authorJesse Williamson <jwilliamson@suse.de>
Mon, 24 Apr 2017 07:43:23 +0000 (00:43 -0700)
committerJesse Williamson <jwilliamson@suse.de>
Mon, 8 May 2017 14:13:57 +0000 (07:13 -0700)
Signed-off-by: Jesse Williamson <jwilliamson@suse.de>
src/tools/rbd/action/MirrorPool.cc
src/tools/rbd_mirror/ImageDeleter.cc
src/tools/rbd_mirror/ImageDeleter.h
src/tools/rbd_mirror/ImageReplayer.h
src/tools/rbd_mirror/Mirror.cc
src/tools/rbd_mirror/Mirror.h
src/tools/rbd_mirror/PoolReplayer.cc
src/tools/rbd_mirror/PoolReplayer.h
src/tools/rbd_nbd/rbd-nbd.cc

index 5e51ca8e1ac38b5d6164940ba3fbc2911e09e3c2..929ac446d02cbeaf87acdf82cbbd7162c58d509a 100644 (file)
@@ -4,7 +4,6 @@
 #include "tools/rbd/ArgumentTypes.h"
 #include "tools/rbd/Shell.h"
 #include "tools/rbd/Utils.h"
-#include "include/atomic.h"
 #include "include/Context.h"
 #include "include/stringify.h"
 #include "include/rbd/librbd.hpp"
@@ -21,6 +20,8 @@
 #include <boost/regex.hpp>
 #include "include/assert.h"
 
+#include <atomic>
+
 #define dout_context g_ceph_context
 #define dout_subsys ceph_subsys_rbd
 #undef dout_prefix
@@ -319,7 +320,7 @@ private:
 class PromoteImageRequest : public ImageRequestBase {
 public:
   PromoteImageRequest(librados::IoCtx &io_ctx, OrderedThrottle &throttle,
-                      const std::string &image_name, atomic_t *counter,
+                      const std::string &image_name, std::atomic<unsigned> *counter,
                       bool force)
     : ImageRequestBase(io_ctx, throttle, image_name), m_counter(counter),
       m_force(force) {
@@ -334,11 +335,11 @@ protected:
                       librbd::RBD::AioCompletion *aio_comp) override {
     image.aio_mirror_image_promote(m_force, aio_comp);
   }
+
   void handle_execute_action(int r) override {
     if (r >= 0) {
-      m_counter->inc();
+      (*m_counter)++;
     }
-    ImageRequestBase::handle_execute_action(r);
   }
 
   std::string get_action_type() const override {
@@ -346,14 +347,14 @@ protected:
   }
 
 private:
-  atomic_t *m_counter;
+  std::atomic<unsigned> *m_counter = nullptr;
   bool m_force;
 };
 
 class DemoteImageRequest : public ImageRequestBase {
 public:
   DemoteImageRequest(librados::IoCtx &io_ctx, OrderedThrottle &throttle,
-                     const std::string &image_name, atomic_t *counter)
+                     const std::string &image_name, std::atomic<unsigned> *counter)
     : ImageRequestBase(io_ctx, throttle, image_name), m_counter(counter) {
   }
 
@@ -368,7 +369,7 @@ protected:
   }
   void handle_execute_action(int r) override {
     if (r >= 0) {
-      m_counter->inc();
+      (*m_counter)++;
     }
     ImageRequestBase::handle_execute_action(r);
   }
@@ -378,7 +379,7 @@ protected:
   }
 
 private:
-  atomic_t *m_counter;
+  std::atomic<unsigned> *m_counter = nullptr;
 };
 
 class StatusImageRequest : public ImageRequestBase {
@@ -915,12 +916,12 @@ int execute_promote(const po::variables_map &vm) {
     return r;
   }
 
-  atomic_t counter;
+  std::atomic<unsigned> counter = { 0 };
   ImageRequestGenerator<PromoteImageRequest> generator(io_ctx, &counter,
                                                        vm["force"].as<bool>());
   r = generator.execute();
 
-  std::cout << "Promoted " << counter.read() << " mirrored images" << std::endl;
+  std::cout << "Promoted " << counter.load() << " mirrored images" << std::endl;
   return r;
 }
 
@@ -940,11 +941,11 @@ int execute_demote(const po::variables_map &vm) {
     return r;
   }
 
-  atomic_t counter;
+  std::atomic<unsigned> counter { 0 };
   ImageRequestGenerator<DemoteImageRequest> generator(io_ctx, &counter);
   r = generator.execute();
 
-  std::cout << "Demoted " << counter.read() << " mirrored images" << std::endl;
+  std::cout << "Demoted " << counter.load() << " mirrored images" << std::endl;
   return r;
 }
 
index 59ffaa291b6b3bae5a7cfe44199ab17eea869342..b2eb615a7e4a240132cca67ad1a65612f9a7dfb4 100644 (file)
@@ -134,7 +134,7 @@ private:
 
 ImageDeleter::ImageDeleter(ContextWQ *work_queue, SafeTimer *timer,
                            Mutex *timer_lock)
-  : m_running(1),
+  : m_running(true),
     m_work_queue(work_queue),
     m_delete_lock("rbd::mirror::ImageDeleter::Delete"),
     m_image_deleter_thread(this),
@@ -149,7 +149,7 @@ ImageDeleter::ImageDeleter(ContextWQ *work_queue, SafeTimer *timer,
 ImageDeleter::~ImageDeleter() {
   dout(20) << "enter" << dendl;
 
-  m_running.set(0);
+  m_running = false;
   {
     Mutex::Locker l (m_delete_lock);
     m_delete_queue_cond.Signal();
@@ -164,13 +164,13 @@ ImageDeleter::~ImageDeleter() {
 
 void ImageDeleter::run() {
   dout(20) << "enter" << dendl;
-  while(m_running.read()) {
+  while(m_running) {
     m_delete_lock.Lock();
     while (m_delete_queue.empty()) {
       dout(20) << "waiting for delete requests" << dendl;
       m_delete_queue_cond.Wait(m_delete_lock);
 
-      if (!m_running.read()) {
+      if (!m_running) {
         m_delete_lock.Unlock();
         dout(20) << "return" << dendl;
         return;
@@ -183,7 +183,7 @@ void ImageDeleter::run() {
 
     bool move_to_next = process_image_delete();
     if (!move_to_next) {
-      if (!m_running.read()) {
+      if (!m_running) {
        dout(20) << "return" << dendl;
        return;
       }
index 9ff990b781c23587b51354766127b765478ad218..c91f2fbc6ff138a3680f2f8bdbf67442c4da5d35 100644 (file)
 #ifndef CEPH_RBD_MIRROR_IMAGEDELETER_H
 #define CEPH_RBD_MIRROR_IMAGEDELETER_H
 
-#include <deque>
-#include <vector>
-#include "include/atomic.h"
 #include "common/Mutex.h"
 #include "common/Cond.h"
 #include "common/Thread.h"
 #include "common/Timer.h"
 #include "types.h"
 
+#include <deque>
+#include <vector>
+#include <atomic>
+
 class ContextWQ;
 
 namespace rbd {
@@ -98,7 +99,7 @@ private:
                       bool print_failure_info=false);
   };
 
-  atomic_t m_running;
+  std::atomic<unsigned> m_running { 0 };
 
   ContextWQ *m_work_queue;
 
index 5fc8bee0ec686a6bf75da6e643e3d313f88a31ea..72f03f77b6cfb35e13aece956e082fd78298e08c 100644 (file)
@@ -4,11 +4,6 @@
 #ifndef CEPH_RBD_MIRROR_IMAGE_REPLAYER_H
 #define CEPH_RBD_MIRROR_IMAGE_REPLAYER_H
 
-#include <map>
-#include <string>
-#include <vector>
-
-#include "include/atomic.h"
 #include "common/AsyncOpTracker.h"
 #include "common/Mutex.h"
 #include "common/WorkQueue.h"
 #include "ImageDeleter.h"
 #include "ProgressContext.h"
 #include "types.h"
-#include <set>
+
 #include <boost/noncopyable.hpp>
 #include <boost/optional.hpp>
 
+#include <set>
+#include <map>
+#include <atomic>
+#include <string>
+#include <vector>
+
 class AdminSocketHook;
 
 namespace journal {
index 86c6939182f5561b0b6363fb7ae2e80d31dca9e9..f37d255992242e7dff4f0bed9bee2c06ad83c49a 100644 (file)
@@ -215,7 +215,7 @@ Mirror::~Mirror()
 
 void Mirror::handle_signal(int signum)
 {
-  m_stopping.set(1);
+  m_stopping = true;
   {
     Mutex::Locker l(m_lock);
     m_cond.Signal();
@@ -250,7 +250,7 @@ int Mirror::init()
 void Mirror::run()
 {
   dout(20) << "enter" << dendl;
-  while (!m_stopping.read()) {
+  while (!m_stopping) {
     m_local_cluster_watcher->refresh_pools();
     Mutex::Locker l(m_lock);
     if (!m_manual_stop) {
@@ -275,7 +275,7 @@ void Mirror::print_status(Formatter *f, stringstream *ss)
 
   Mutex::Locker l(m_lock);
 
-  if (m_stopping.read()) {
+  if (m_stopping) {
     return;
   }
 
@@ -314,7 +314,7 @@ void Mirror::start()
   dout(20) << "enter" << dendl;
   Mutex::Locker l(m_lock);
 
-  if (m_stopping.read()) {
+  if (m_stopping) {
     return;
   }
 
@@ -330,7 +330,7 @@ void Mirror::stop()
   dout(20) << "enter" << dendl;
   Mutex::Locker l(m_lock);
 
-  if (m_stopping.read()) {
+  if (m_stopping) {
     return;
   }
 
@@ -346,7 +346,7 @@ void Mirror::restart()
   dout(20) << "enter" << dendl;
   Mutex::Locker l(m_lock);
 
-  if (m_stopping.read()) {
+  if (m_stopping) {
     return;
   }
 
@@ -362,7 +362,7 @@ void Mirror::flush()
   dout(20) << "enter" << dendl;
   Mutex::Locker l(m_lock);
 
-  if (m_stopping.read() || m_manual_stop) {
+  if (m_stopping || m_manual_stop) {
     return;
   }
 
@@ -376,7 +376,7 @@ void Mirror::release_leader()
   dout(20) << "enter" << dendl;
   Mutex::Locker l(m_lock);
 
-  if (m_stopping.read()) {
+  if (m_stopping) {
     return;
   }
 
index 4ff9d512399aeb51f8212d5d37c44ff1fb4f906a..88d15cfc8053071c624d29599dd3da888b67ba80 100644 (file)
@@ -4,19 +4,19 @@
 #ifndef CEPH_RBD_MIRROR_H
 #define CEPH_RBD_MIRROR_H
 
-#include <map>
-#include <memory>
-#include <set>
-
 #include "common/ceph_context.h"
 #include "common/Mutex.h"
-#include "include/atomic.h"
 #include "include/rados/librados.hpp"
 #include "ClusterWatcher.h"
 #include "PoolReplayer.h"
 #include "ImageDeleter.h"
 #include "types.h"
 
+#include <set>
+#include <map>
+#include <memory>
+#include <atomic>
+
 namespace librbd { struct ImageCtx; }
 
 namespace rbd {
index 0dbfeffe54d4892a525f5cddcb5c9a8db12e5a47..751b46c20565bca6d12964eef3f994033ba46f47 100644 (file)
@@ -229,7 +229,7 @@ PoolReplayer::~PoolReplayer()
 {
   delete m_asok_hook;
 
-  m_stopping.set(1);
+  m_stopping = true;
   {
     Mutex::Locker l(m_lock);
     m_cond.Signal();
@@ -410,7 +410,7 @@ void PoolReplayer::run()
 {
   dout(20) << "enter" << dendl;
 
-  while (!m_stopping.read()) {
+  while (!m_stopping) {
     std::string asok_hook_name = m_local_io_ctx.get_pool_name() + " " +
                                  m_peer.cluster_name;
     if (m_asok_hook_name != asok_hook_name || m_asok_hook == nullptr) {
@@ -425,7 +425,7 @@ void PoolReplayer::run()
     if ((m_local_pool_watcher && m_local_pool_watcher->is_blacklisted()) ||
        (m_remote_pool_watcher && m_remote_pool_watcher->is_blacklisted())) {
       m_blacklisted = true;
-      m_stopping.set(1);
+      m_stopping = true;
       break;
     }
 
@@ -476,7 +476,7 @@ void PoolReplayer::start()
 
   Mutex::Locker l(m_lock);
 
-  if (m_stopping.read()) {
+  if (m_stopping) {
     return;
   }
 
@@ -489,10 +489,10 @@ void PoolReplayer::stop(bool manual)
 
   Mutex::Locker l(m_lock);
   if (!manual) {
-    m_stopping.set(1);
+    m_stopping = true;
     m_cond.Signal();
     return;
-  } else if (m_stopping.read()) {
+  } else if (m_stopping) {
     return;
   }
 
@@ -505,7 +505,7 @@ void PoolReplayer::restart()
 
   Mutex::Locker l(m_lock);
 
-  if (m_stopping.read()) {
+  if (m_stopping) {
     return;
   }
 
@@ -518,7 +518,7 @@ void PoolReplayer::flush()
 
   Mutex::Locker l(m_lock);
 
-  if (m_stopping.read() || m_manual_stop) {
+  if (m_stopping || m_manual_stop) {
     return;
   }
 
@@ -531,7 +531,7 @@ void PoolReplayer::release_leader()
 
   Mutex::Locker l(m_lock);
 
-  if (m_stopping.read() || !m_leader_watcher) {
+  if (m_stopping || !m_leader_watcher) {
     return;
   }
 
@@ -541,7 +541,7 @@ void PoolReplayer::release_leader()
 void PoolReplayer::handle_update(const std::string &mirror_uuid,
                                 ImageIds &&added_image_ids,
                                 ImageIds &&removed_image_ids) {
-  if (m_stopping.read()) {
+  if (m_stopping) {
     return;
   }
 
index 620b6db9a5e7ca0df5c584ab3429503961db40fe..55fdcedf3c38cffb1225a07af8f6ede4036c091b 100644 (file)
@@ -4,16 +4,10 @@
 #ifndef CEPH_RBD_MIRROR_POOL_REPLAYER_H
 #define CEPH_RBD_MIRROR_POOL_REPLAYER_H
 
-#include <map>
-#include <memory>
-#include <set>
-#include <string>
-
 #include "common/AsyncOpTracker.h"
 #include "common/Cond.h"
 #include "common/Mutex.h"
 #include "common/WorkQueue.h"
-#include "include/atomic.h"
 #include "include/rados/librados.hpp"
 
 #include "ClusterWatcher.h"
 #include "ImageDeleter.h"
 #include "types.h"
 
+#include <set>
+#include <map>
+#include <memory>
+#include <atomic>
+#include <string>
+
 class AdminSocketHook;
 
 namespace librbd { class ImageCtx; }
index 8ba83208b2e0a4fafbee6b7b9df1149df84d81d0..62ccd2c1fe609a5a4a5772e1138677fa314d1826 100644 (file)
@@ -113,7 +113,6 @@ public:
   NBDServer(int _fd, librbd::Image& _image)
     : fd(_fd)
     , image(_image)
-    , terminated(false)
     , lock("NBDServer::Locker")
     , reader_thread(*this, &NBDServer::reader_entry)
     , writer_thread(*this, &NBDServer::writer_entry)
@@ -121,11 +120,12 @@ public:
   {}
 
 private:
-  atomic_t terminated;
+  std::atomic<bool> terminated = { false };
 
   void shutdown()
   {
-    if (terminated.compare_and_swap(false, true)) {
+    bool expected = false;
+    if (terminated.compare_exchange_weak(expected, true)) {
       ::shutdown(fd, SHUT_RDWR);
 
       Mutex::Locker l(lock);
@@ -172,7 +172,7 @@ private:
   IOContext *wait_io_finish()
   {
     Mutex::Locker l(lock);
-    while(io_finished.empty() && !terminated.read())
+    while(io_finished.empty() && !terminated)
       cond.Wait(lock);
 
     if (io_finished.empty())
@@ -234,7 +234,7 @@ private:
 
   void reader_entry()
   {
-    while (!terminated.read()) {
+    while (!terminated) {
       ceph::unique_ptr<IOContext> ctx(new IOContext());
       ctx->server = this;
 
@@ -309,7 +309,7 @@ private:
 
   void writer_entry()
   {
-    while (!terminated.read()) {
+    while (!terminated) {
       dout(20) << __func__ << ": waiting for io request" << dendl;
       ceph::unique_ptr<IOContext> ctx(wait_io_finish());
       if (!ctx) {