From daee9dbe89c641876a01e09b97a52fd109cf9def Mon Sep 17 00:00:00 2001 From: Samuel Just Date: Wed, 12 Jun 2013 13:18:00 -0700 Subject: [PATCH] ObjectStore,Context: add register_on_complete Signed-off-by: Samuel Just --- src/include/Context.h | 20 ++++++++++++++++++++ src/os/ObjectStore.cc | 19 ------------------- src/os/ObjectStore.h | 5 +++++ 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/include/Context.h b/src/include/Context.h index f2416a075d6f3..e31fca6a42627 100644 --- a/src/include/Context.h +++ b/src/include/Context.h @@ -23,6 +23,7 @@ #include #include +#include #define mydout(cct, v) lgeneric_subdout(cct, context, v) @@ -54,6 +55,25 @@ public: void finish(int r) {} }; +template +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 RunOnDeleteRef; /* * finish and destroy a list of Contexts diff --git a/src/os/ObjectStore.cc b/src/os/ObjectStore.cc index 437549d0b393e..eccc90359c55a 100644 --- a/src/os/ObjectStore.cc +++ b/src/os/ObjectStore.cc @@ -41,25 +41,6 @@ unsigned ObjectStore::apply_transactions(Sequencer *osr, return r; } -template -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 RunOnDeleteRef; int ObjectStore::queue_transactions( Sequencer *osr, list& tls, diff --git a/src/os/ObjectStore.h b/src/os/ObjectStore.h index b5e23b16cbe9f..3bcc6e90f4c31 100644 --- a/src/os/ObjectStore.h +++ b/src/os/ObjectStore.h @@ -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(_complete)); + register_on_commit(new ContainerContext(_complete)); + } static void collect_contexts( list &t, -- 2.39.5