From 85ba9a36673a9049b8cc8fb9418d4ae6fad1fc67 Mon Sep 17 00:00:00 2001 From: John Spray Date: Thu, 30 Jun 2016 13:13:34 +0100 Subject: [PATCH] mon: add with_monmap to MonClient Analogous to Objecter::with_osdmap, for safe access to the map. Signed-off-by: John Spray --- src/mon/MonClient.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/mon/MonClient.h b/src/mon/MonClient.h index dd88fb0fcc24a..cc1f9bd4df5d6 100644 --- a/src/mon/MonClient.h +++ b/src/mon/MonClient.h @@ -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 + auto with_monmap(Callback&& cb, Args&&...args) -> + typename std::enable_if< + std::is_void< + decltype(cb(const_cast(monmap), + std::forward(args)...))>::value, + void>::type { + Mutex::Locker l(monc_lock); + std::forward(cb)(const_cast(monmap), + std::forward(args)...); + } + private: struct version_req_d { Context *context; -- 2.39.5