]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: add RGWAioCompletionNotifierWith<T>
authorCasey Bodley <cbodley@redhat.com>
Fri, 17 Aug 2018 17:40:25 +0000 (13:40 -0400)
committerNathan Cutler <ncutler@suse.com>
Sat, 3 Nov 2018 14:24:14 +0000 (15:24 +0100)
Signed-off-by: Casey Bodley <cbodley@redhat.com>
(cherry picked from commit de4376f0405c8c172651bbd27f370b63d03614a8)

src/rgw/rgw_coroutine.h

index 7212a4fc84a11b3ad2d2c0b3c1fd1ed253960d22..ea55adbf892055e3a7dd27c8ee4061e61df53da0 100644 (file)
@@ -135,6 +135,18 @@ public:
   }
 };
 
+// completion notifier with opaque payload (ie a reference-counted pointer)
+template <typename T>
+class RGWAioCompletionNotifierWith : public RGWAioCompletionNotifier {
+  T value;
+public:
+  RGWAioCompletionNotifierWith(RGWCompletionManager *mgr,
+                               const rgw_io_id& io_id, void *user_data,
+                               T value)
+    : RGWAioCompletionNotifier(mgr, io_id, user_data), value(std::move(value))
+  {}
+};
+
 struct RGWCoroutinesEnv {
   uint64_t run_context;
   RGWCoroutinesManager *manager;
@@ -479,6 +491,8 @@ public:
   void cancel();
 
   RGWAioCompletionNotifier *create_completion_notifier();
+  template <typename T>
+  RGWAioCompletionNotifier *create_completion_notifier(T value);
   RGWCompletionManager *get_completion_mgr();
 
   void set_blocked_by(RGWCoroutinesStack *s) {
@@ -596,6 +610,8 @@ public:
   virtual void report_error(RGWCoroutinesStack *op);
 
   RGWAioCompletionNotifier *create_completion_notifier(RGWCoroutinesStack *stack);
+  template <typename T>
+  RGWAioCompletionNotifier *create_completion_notifier(RGWCoroutinesStack *stack, T value);
   RGWCompletionManager *get_completion_mgr() { return completion_mgr; }
 
   void schedule(RGWCoroutinesEnv *env, RGWCoroutinesStack *stack);
@@ -615,6 +631,21 @@ public:
   }
 };
 
+template <typename T>
+RGWAioCompletionNotifier *RGWCoroutinesManager::create_completion_notifier(RGWCoroutinesStack *stack, T value)
+{
+  rgw_io_id io_id{get_next_io_id(), -1};
+  RGWAioCompletionNotifier *cn = new RGWAioCompletionNotifierWith<T>(completion_mgr, io_id, (void *)stack, std::move(value));
+  completion_mgr->register_completion_notifier(cn);
+  return cn;
+}
+
+template <typename T>
+RGWAioCompletionNotifier *RGWCoroutinesStack::create_completion_notifier(T value)
+{
+  return ops_mgr->create_completion_notifier(this, std::move(value));
+}
+
 class RGWSimpleCoroutine : public RGWCoroutine {
   bool called_cleanup;