]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr,mon,osdc: more constness
authorKefu Chai <kchai@redhat.com>
Sat, 8 Apr 2017 19:42:03 +0000 (03:42 +0800)
committerKefu Chai <kchai@redhat.com>
Mon, 10 Apr 2017 15:20:16 +0000 (23:20 +0800)
Signed-off-by: Kefu Chai <kchai@redhat.com>
src/mgr/ClusterState.h
src/mon/MonClient.h
src/osdc/Objecter.h

index eced72ad90e465483c735495b8a64d4517e0cb93..fb967e17fc1969af0ed70d61817120818e9fb237 100644 (file)
@@ -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<typename Callback, typename...Args>
-  void with_fsmap(Callback&& cb, Args&&...args)
+  void with_fsmap(Callback&& cb, Args&&...args) const
   {
     Mutex::Locker l(lock);
-    std::forward<Callback>(cb)(const_cast<const FSMap&>(fsmap),
-        std::forward<Args>(args)...);
+    std::forward<Callback>(cb)(fsmap, std::forward<Args>(args)...);
   }
 
   template<typename Callback, typename...Args>
-  auto with_pgmap(Callback&& cb, Args&&...args) ->
-    decltype(cb(const_cast<const PGMap&>(pg_map),
-               std::forward<Args>(args)...))
+  auto with_pgmap(Callback&& cb, Args&&...args) const ->
+    decltype(cb(pg_map, std::forward<Args>(args)...))
   {
     Mutex::Locker l(lock);
-    return std::forward<Callback>(cb)(const_cast<const PGMap&>(pg_map),
-                                     std::forward<Args>(args)...);
+    return std::forward<Callback>(cb)(pg_map, std::forward<Args>(args)...);
   }
 
   template<typename... Args>
-  void with_monmap(Args &&... args)
+  void with_monmap(Args &&... args) const
   {
     Mutex::Locker l(lock);
     assert(monc != nullptr);
@@ -89,7 +86,7 @@ public:
   }
 
   template<typename... Args>
-  auto with_osdmap(Args &&... args) ->
+  auto with_osdmap(Args &&... args) const ->
     decltype(objecter->with_osdmap(std::forward<Args>(args)...))
   {
     assert(objecter != nullptr);
index 22add022c2a9c62e311f8d54703c4046aa1427a8..283e889fda7c3c9d39d16497096b5421cc8c28f7 100644 (file)
@@ -466,12 +466,10 @@ public:
    * to the MonMap
    */
   template<typename Callback, typename...Args>
-  auto with_monmap(Callback&& cb, Args&&...args) ->
-    decltype(cb(const_cast<const MonMap&>(monmap),
-               std::forward<Args>(args)...)) {
+  auto with_monmap(Callback&& cb, Args&&...args) const ->
+    decltype(cb(monmap, std::forward<Args>(args)...)) {
     Mutex::Locker l(monc_lock);
-    return std::forward<Callback>(cb)(const_cast<const MonMap&>(monmap),
-                                     std::forward<Args>(args)...);
+    return std::forward<Callback>(cb)(monmap, std::forward<Args>(args)...);
   }
 
 private:
index 9f73ca6a9826941be1c3daa2d2b57a2b1d9dd8cf..19efc5006855ec6bab4e69d58da75ffa0dc8d6e5 100644 (file)
@@ -1952,12 +1952,10 @@ private:
   // here or you will have great woe and misery.
 
   template<typename Callback, typename...Args>
-  auto with_osdmap(Callback&& cb, Args&&... args) ->
-    decltype(cb(const_cast<const OSDMap&>(*osdmap),
-               std::forward<Args>(args)...)) {
+  auto with_osdmap(Callback&& cb, Args&&... args) const ->
+    decltype(cb(*osdmap, std::forward<Args>(args)...)) {
     shared_lock l(rwlock);
-    return std::forward<Callback>(cb)(const_cast<const OSDMap&>(*osdmap),
-                                     std::forward<Args>(args)...);
+    return std::forward<Callback>(cb)(*osdmap, std::forward<Args>(args)...);
   }