From: Kefu Chai Date: Sat, 8 Apr 2017 19:42:03 +0000 (+0800) Subject: mgr,mon,osdc: more constness X-Git-Tag: v12.0.2~83^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=6646b35ac76d518f7d764724b8a2cf7e4f8356ee;p=ceph.git mgr,mon,osdc: more constness Signed-off-by: Kefu Chai --- diff --git a/src/mgr/ClusterState.h b/src/mgr/ClusterState.h index eced72ad90e4..fb967e17fc19 100644 --- a/src/mgr/ClusterState.h +++ b/src/mgr/ClusterState.h @@ -35,7 +35,7 @@ protected: MonClient *monc; Objecter *objecter; FSMap fsmap; - Mutex lock; + mutable Mutex lock; PGMap pg_map; @@ -57,31 +57,28 @@ public: void notify_osdmap(const OSDMap &osd_map); - bool have_fsmap() { + bool have_fsmap() const { Mutex::Locker l(lock); return fsmap.get_epoch() > 0; } template - void with_fsmap(Callback&& cb, Args&&...args) + void with_fsmap(Callback&& cb, Args&&...args) const { Mutex::Locker l(lock); - std::forward(cb)(const_cast(fsmap), - std::forward(args)...); + std::forward(cb)(fsmap, std::forward(args)...); } template - auto with_pgmap(Callback&& cb, Args&&...args) -> - decltype(cb(const_cast(pg_map), - std::forward(args)...)) + auto with_pgmap(Callback&& cb, Args&&...args) const -> + decltype(cb(pg_map, std::forward(args)...)) { Mutex::Locker l(lock); - return std::forward(cb)(const_cast(pg_map), - std::forward(args)...); + return std::forward(cb)(pg_map, std::forward(args)...); } template - void with_monmap(Args &&... args) + void with_monmap(Args &&... args) const { Mutex::Locker l(lock); assert(monc != nullptr); @@ -89,7 +86,7 @@ public: } template - auto with_osdmap(Args &&... args) -> + auto with_osdmap(Args &&... args) const -> decltype(objecter->with_osdmap(std::forward(args)...)) { assert(objecter != nullptr); diff --git a/src/mon/MonClient.h b/src/mon/MonClient.h index 22add022c2a9..283e889fda7c 100644 --- a/src/mon/MonClient.h +++ b/src/mon/MonClient.h @@ -466,12 +466,10 @@ public: * to the MonMap */ template - auto with_monmap(Callback&& cb, Args&&...args) -> - decltype(cb(const_cast(monmap), - std::forward(args)...)) { + auto with_monmap(Callback&& cb, Args&&...args) const -> + decltype(cb(monmap, std::forward(args)...)) { Mutex::Locker l(monc_lock); - return std::forward(cb)(const_cast(monmap), - std::forward(args)...); + return std::forward(cb)(monmap, std::forward(args)...); } private: diff --git a/src/osdc/Objecter.h b/src/osdc/Objecter.h index 9f73ca6a9826..19efc5006855 100644 --- a/src/osdc/Objecter.h +++ b/src/osdc/Objecter.h @@ -1952,12 +1952,10 @@ private: // here or you will have great woe and misery. template - auto with_osdmap(Callback&& cb, Args&&... args) -> - decltype(cb(const_cast(*osdmap), - std::forward(args)...)) { + auto with_osdmap(Callback&& cb, Args&&... args) const -> + decltype(cb(*osdmap, std::forward(args)...)) { shared_lock l(rwlock); - return std::forward(cb)(const_cast(*osdmap), - std::forward(args)...); + return std::forward(cb)(*osdmap, std::forward(args)...); }