]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
include/Context: add generic C_Lock
authorSage Weil <sage@redhat.com>
Mon, 21 Jul 2014 03:47:22 +0000 (20:47 -0700)
committerJohn Spray <john.spray@redhat.com>
Mon, 25 Aug 2014 00:34:02 +0000 (01:34 +0100)
Wrap a callback in a Mutex.

Signed-off-by: Sage Weil <sage@redhat.com>
src/include/Context.h

index 38af84325aed12a8028a9eb158a63b84db1f7b6e..d9533c5b61068c66b15bc22e6492151a64ccbc05 100644 (file)
@@ -148,6 +148,23 @@ public:
 };
 
 
+struct C_Lock : public Context {
+  Mutex *lock;
+  Context *fin;
+  C_Lock(Mutex *l, Context *c) : lock(l), fin(c) {}
+  ~C_Lock() {
+    delete fin;
+  }
+  void finish(int r) {
+    if (fin) {
+      lock->Lock();
+      fin->complete(r);
+      fin = NULL;
+      lock->Unlock();
+    }
+  }
+};
+
 /*
  * C_Contexts - set of Contexts
  */