]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ObjectStore,Context: add register_on_complete
authorSamuel Just <sam.just@inktank.com>
Wed, 12 Jun 2013 20:18:00 +0000 (13:18 -0700)
committerSamuel Just <sam.just@inktank.com>
Wed, 3 Jul 2013 20:58:11 +0000 (13:58 -0700)
Signed-off-by: Samuel Just <sam.just@inktank.com>
src/include/Context.h
src/os/ObjectStore.cc
src/os/ObjectStore.h

index f2416a075d6f3c76ca5985e4fc917fb7cd65640d..e31fca6a4262766090848d14531999cae90c217f 100644 (file)
@@ -23,6 +23,7 @@
 #include <set>
 
 #include <iostream>
+#include <tr1/memory>
 
 #define mydout(cct, v) lgeneric_subdout(cct, context, v)
 
@@ -54,6 +55,25 @@ public:
   void finish(int r) {}
 };
 
+template <class T>
+struct Wrapper : public Context {
+  Context *to_run;
+  T val;
+  Wrapper(Context *to_run, T val) : to_run(to_run), val(val) {}
+  void finish(int r) {
+    if (to_run)
+      to_run->complete(r);
+  }
+};
+struct RunOnDelete {
+  Context *to_run;
+  RunOnDelete(Context *to_run) : to_run(to_run) {}
+  ~RunOnDelete() {
+    if (to_run)
+      to_run->complete(0);
+  }
+};
+typedef std::tr1::shared_ptr<RunOnDelete> RunOnDeleteRef;
 
 /*
  * finish and destroy a list of Contexts
index 437549d0b393e013719a0fe52b6cd3738a058ce6..eccc90359c55a77a6a2d421361ca0562a220e178 100644 (file)
@@ -41,25 +41,6 @@ unsigned ObjectStore::apply_transactions(Sequencer *osr,
   return r;
 }
 
-template <class T>
-struct Wrapper : public Context {
-  Context *to_run;
-  T val;
-  Wrapper(Context *to_run, T val) : to_run(to_run), val(val) {}
-  void finish(int r) {
-    if (to_run)
-      to_run->complete(r);
-  }
-};
-struct RunOnDelete {
-  Context *to_run;
-  RunOnDelete(Context *to_run) : to_run(to_run) {}
-  ~RunOnDelete() {
-    if (to_run)
-      to_run->complete(0);
-  }
-};
-typedef std::tr1::shared_ptr<RunOnDelete> RunOnDeleteRef;
 int ObjectStore::queue_transactions(
   Sequencer *osr,
   list<Transaction*>& tls,
index b5e23b16cbe9f50602408d7f52c27932c7eb099a..3bcc6e90f4c31ae4ba0bb75aa4dbb6eefa63299a 100644 (file)
@@ -186,6 +186,11 @@ public:
     void register_on_applied_sync(Context *c) {
       on_applied_sync.push_back(c);
     }
+    void register_on_complete(Context *c) {
+      RunOnDeleteRef _complete(new RunOnDelete(c));
+      register_on_applied(new ContainerContext<RunOnDeleteRef>(_complete));
+      register_on_commit(new ContainerContext<RunOnDeleteRef>(_complete));
+    }
 
     static void collect_contexts(
       list<Transaction *> &t,