]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: add with_monmap to MonClient
authorJohn Spray <john.spray@redhat.com>
Thu, 30 Jun 2016 12:13:34 +0000 (13:13 +0100)
committerJohn Spray <john.spray@redhat.com>
Thu, 29 Sep 2016 16:26:51 +0000 (17:26 +0100)
Analogous to Objecter::with_osdmap, for safe access
to the map.

Signed-off-by: John Spray <john.spray@redhat.com>
src/mon/MonClient.h

index dd88fb0fcc24acc653191fabdf5ebfdb7364fe65..cc1f9bd4df5d6df1da6fee33a19e45fbf7f02b1a 100644 (file)
@@ -431,6 +431,22 @@ public:
    */
   void get_version(string map, version_t *newest, version_t *oldest, Context *onfinish);
 
+  /**
+   * Run a callback within our lock, with a reference
+   * to the MonMap
+   */
+  template<typename Callback, typename...Args>
+  auto with_monmap(Callback&& cb, Args&&...args) ->
+    typename std::enable_if<
+      std::is_void<
+    decltype(cb(const_cast<const MonMap&>(monmap),
+               std::forward<Args>(args)...))>::value,
+      void>::type {
+    Mutex::Locker l(monc_lock);
+    std::forward<Callback>(cb)(const_cast<const MonMap&>(monmap),
+                              std::forward<Args>(args)...);
+  }
+
 private:
   struct version_req_d {
     Context *context;