]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
librbd: migrate atomic_t to std::atomic<>
authorJesse Williamson <jwilliamson@suse.de>
Sun, 16 Apr 2017 08:31:16 +0000 (01:31 -0700)
committerJesse Williamson <jwilliamson@suse.de>
Mon, 8 May 2017 14:14:04 +0000 (07:14 -0700)
Signed-off-by: Jesse Williamson <jwilliamson@suse.de>
src/librbd/Journal.h
src/librbd/Utils.h
src/librbd/Watcher.cc
src/librbd/io/CopyupRequest.cc
src/librbd/io/CopyupRequest.h
src/librbd/io/ImageRequestWQ.cc
src/librbd/io/ImageRequestWQ.h

index b0db6e6ec06c02ef09091180aa78b57b77246908..3e3cf4928ddb6547f566f286ff9496937b872603 100644 (file)
@@ -5,7 +5,6 @@
 #define CEPH_LIBRBD_JOURNAL_H
 
 #include "include/int_types.h"
-#include "include/atomic.h"
 #include "include/Context.h"
 #include "include/interval_set.h"
 #include "common/Cond.h"
 #include "librbd/Utils.h"
 #include "librbd/journal/Types.h"
 #include "librbd/journal/TypeTraits.h"
+
 #include <algorithm>
 #include <list>
 #include <string>
+#include <atomic>
 #include <unordered_map>
 
 class SafeTimer;
@@ -155,7 +156,7 @@ public:
   void wait_event(uint64_t tid, Context *on_safe);
 
   uint64_t allocate_op_tid() {
-    uint64_t op_tid = m_op_tid.inc();
+    uint64_t op_tid = ++m_op_tid;
     assert(op_tid != 0);
     return op_tid;
   }
@@ -297,7 +298,7 @@ private:
   uint64_t m_event_tid;
   Events m_events;
 
-  atomic_t m_op_tid;
+  std::atomic<uint64_t> m_op_tid = { 0 };
   TidToFutures m_op_futures;
 
   bool m_processing_entry = false;
index ce98d3ad6e3c50d65554ccb1de947bce5776afc0..9a30860531ec21116f67bd6504d7d59164f2cf8e 100644 (file)
@@ -7,6 +7,8 @@
 #include "include/rados/librados.hpp"
 #include "include/rbd_types.h"
 #include "include/Context.h"
+
+#include <atomic>
 #include <type_traits>
 
 namespace librbd {
@@ -153,15 +155,12 @@ inline ImageCtx *get_image_ctx(ImageCtx *image_ctx) {
 /// a shut down of the invoking class instance
 class AsyncOpTracker {
 public:
-  AsyncOpTracker() : m_refs(0) {
-  }
-
   void start_op() {
-    m_refs.inc();
+    m_refs++;
   }
 
   void finish_op() {
-    if (m_refs.dec() == 0 && m_on_finish != nullptr) {
+    if (--m_refs == 0 && m_on_finish != nullptr) {
       Context *on_finish = nullptr;
       std::swap(on_finish, m_on_finish);
       on_finish->complete(0);
@@ -173,7 +172,7 @@ public:
     assert(m_on_finish == nullptr);
 
     on_finish = create_async_context_callback(image_ctx, on_finish);
-    if (m_refs.read() == 0) {
+    if (m_refs == 0) {
       on_finish->complete(0);
       return;
     }
@@ -181,7 +180,7 @@ public:
   }
 
 private:
-  atomic_t m_refs;
+  std::atomic<uint64_t> m_refs = { 0 };
   Context *m_on_finish = nullptr;
 };
 
index 2964918dc670570e2e7b61d902d53b03208767d4..98a0e7f0be42d4c8a9d1348e83f5bb1d49112072 100644 (file)
@@ -10,6 +10,9 @@
 #include "common/WorkQueue.h"
 #include <boost/bind.hpp>
 
+// re-include our assert to clobber the system one; fix dout:
+#include "include/assert.h"
+
 #define dout_subsys ceph_subsys_rbd
 
 namespace librbd {
index b11dbad27b6304c2a4d40376eb752fdee6eb79a7..9ce36388d080abf80cd4ff71736af510ccda01c9 100644 (file)
@@ -128,7 +128,7 @@ bool CopyupRequest::send_copyup() {
   std::vector<librados::snap_t> snaps;
 
   if (!copy_on_read) {
-    m_pending_copyups.inc();
+    m_pending_copyups++;
   }
 
   int r;
@@ -143,7 +143,7 @@ bool CopyupRequest::send_copyup() {
     // all snapshots are detected from the parent for this object.  If
     // this is a CoW request, a second request will be created for the
     // actual modification.
-    m_pending_copyups.inc();
+    m_pending_copyups++;
 
     ldout(m_ictx->cct, 20) << __func__ << " " << this << " copyup with "
                            << "empty snapshot context" << dendl;
@@ -252,7 +252,7 @@ bool CopyupRequest::should_complete(int r)
 
   case STATE_COPYUP:
     // invoked via a finisher in librados, so thread safe
-    pending_copyups = m_pending_copyups.dec();
+    pending_copyups = --m_pending_copyups;
     ldout(cct, 20) << "COPYUP (" << pending_copyups << " pending)"
                    << dendl;
     if (r == -ENOENT) {
index d0183705c5f8c73a7647648acc0f854dda93a87c..d2902029c293d2fcd32089d41120db6498f9616d 100644 (file)
@@ -5,13 +5,14 @@
 #define CEPH_LIBRBD_IO_COPYUP_REQUEST_H
 
 #include "librbd/AsyncOperation.h"
-#include "include/atomic.h"
 #include "include/int_types.h"
 #include "include/rados/librados.hpp"
 #include "include/buffer.h"
 #include "librbd/io/Types.h"
+
 #include <string>
 #include <vector>
+#include <atomic>
 
 namespace librbd {
 
@@ -79,7 +80,7 @@ private:
   State m_state;
   ceph::bufferlist m_copyup_data;
   std::vector<ObjectRequest<ImageCtx> *> m_pending_requests;
-  atomic_t m_pending_copyups;
+  std::atomic<unsigned> m_pending_copyups { 0 };
 
   AsyncOperation m_async_op;
 
index d616114121655cd67e60bbc35df4d23ed97a8936..d45a658bca21975005e1eb3c027e81c558d29331 100644 (file)
@@ -275,9 +275,9 @@ void ImageRequestWQ::shut_down(Context *on_shutdown) {
     m_shutdown = true;
 
     CephContext *cct = m_image_ctx.cct;
-    ldout(cct, 5) << __func__ << ": in_flight=" << m_in_flight_ops.read()
+    ldout(cct, 5) << __func__ << ": in_flight=" << m_in_flight_ops.load()
                   << dendl;
-    if (m_in_flight_ops.read() > 0) {
+    if (m_in_flight_ops > 0) {
       m_on_shutdown = on_shutdown;
       return;
     }
@@ -289,8 +289,8 @@ void ImageRequestWQ::shut_down(Context *on_shutdown) {
 
 bool ImageRequestWQ::is_lock_request_needed() const {
   RWLock::RLocker locker(m_lock);
-  return (m_queued_writes.read() > 0 ||
-          (m_require_lock_on_read && m_queued_reads.read() > 0));
+  return (m_queued_writes > 0 ||
+          (m_require_lock_on_read && m_queued_reads > 0));
 }
 
 int ImageRequestWQ::block_writes() {
@@ -308,7 +308,7 @@ void ImageRequestWQ::block_writes(Context *on_blocked) {
     ++m_write_blockers;
     ldout(cct, 5) << __func__ << ": " << &m_image_ctx << ", "
                   << "num=" << m_write_blockers << dendl;
-    if (!m_write_blocker_contexts.empty() || m_in_progress_writes.read() > 0) {
+    if (!m_write_blocker_contexts.empty() || m_in_progress_writes > 0) {
       m_write_blocker_contexts.push_back(on_blocked);
       return;
     }
@@ -380,7 +380,7 @@ void *ImageRequestWQ::_void_dequeue() {
 
       // refresh will requeue the op -- don't count it as in-progress
       if (!refresh_required) {
-        m_in_progress_writes.inc();
+        m_in_progress_writes++;
       }
     } else if (m_require_lock_on_read) {
       return nullptr;
@@ -427,11 +427,11 @@ void ImageRequestWQ::process(ImageRequest<> *req) {
 void ImageRequestWQ::finish_queued_op(ImageRequest<> *req) {
   RWLock::RLocker locker(m_lock);
   if (req->is_write_op()) {
-    assert(m_queued_writes.read() > 0);
-    m_queued_writes.dec();
+    assert(m_queued_writes > 0);
+    m_queued_writes--;
   } else {
-    assert(m_queued_reads.read() > 0);
-    m_queued_reads.dec();
+    assert(m_queued_reads > 0);
+    m_queued_reads--;
   }
 }
 
@@ -439,8 +439,8 @@ void ImageRequestWQ::finish_in_progress_write() {
   bool writes_blocked = false;
   {
     RWLock::RLocker locker(m_lock);
-    assert(m_in_progress_writes.read() > 0);
-    if (m_in_progress_writes.dec() == 0 &&
+    assert(m_in_progress_writes > 0);
+    if (--m_in_progress_writes == 0 &&
         !m_write_blocker_contexts.empty()) {
       writes_blocked = true;
     }
@@ -462,7 +462,7 @@ int ImageRequestWQ::start_in_flight_op(AioCompletion *c) {
     return false;
   }
 
-  m_in_flight_ops.inc();
+  m_in_flight_ops++;
   return true;
 }
 
@@ -470,7 +470,7 @@ void ImageRequestWQ::finish_in_flight_op() {
   Context *on_shutdown;
   {
     RWLock::RLocker locker(m_lock);
-    if (m_in_flight_ops.dec() > 0 || !m_shutdown) {
+    if (--m_in_flight_ops > 0 || !m_shutdown) {
       return;
     }
     on_shutdown = m_on_shutdown;
@@ -512,9 +512,9 @@ void ImageRequestWQ::queue(ImageRequest<> *req) {
   }
 
   if (write_op) {
-    m_queued_writes.inc();
+    m_queued_writes++;
   } else {
-    m_queued_reads.inc();
+    m_queued_reads++;
   }
 
   ThreadPool::PointerWQ<ImageRequest<> >::queue(req);
index f5a8d955da5c461abed17e4e687cd945597bddb7..0ed843dafebd4ef649b7b8a157f2942315cea0ad 100644 (file)
@@ -5,10 +5,11 @@
 #define CEPH_LIBRBD_IO_IMAGE_REQUEST_WQ_H
 
 #include "include/Context.h"
-#include "include/atomic.h"
 #include "common/RWLock.h"
 #include "common/WorkQueue.h"
+
 #include <list>
+#include <atomic>
 
 namespace librbd {
 
@@ -98,10 +99,10 @@ private:
   Contexts m_write_blocker_contexts;
   uint32_t m_write_blockers;
   bool m_require_lock_on_read = false;
-  atomic_t m_in_progress_writes;
-  atomic_t m_queued_reads;
-  atomic_t m_queued_writes;
-  atomic_t m_in_flight_ops;
+  std::atomic<unsigned> m_in_progress_writes { 0 };
+  std::atomic<unsigned> m_queued_reads { 0 };
+  std::atomic<unsigned> m_queued_writes { 0 };
+  std::atomic<unsigned> m_in_flight_ops { 0 };
 
   bool m_refresh_in_progress;
 
@@ -110,7 +111,7 @@ private:
 
   inline bool writes_empty() const {
     RWLock::RLocker locker(m_lock);
-    return (m_queued_writes.read() == 0);
+    return (m_queued_writes == 0);
   }
 
   void finish_queued_op(ImageRequest<ImageCtx> *req);