]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common/config: extract LockMutex and LockPolicy out
authorKefu Chai <kchai@redhat.com>
Wed, 27 Jun 2018 07:36:29 +0000 (15:36 +0800)
committerKefu Chai <kchai@redhat.com>
Wed, 27 Jun 2018 13:41:02 +0000 (21:41 +0800)
Signed-off-by: Kefu Chai <kchai@redhat.com>
src/common/config.cc
src/common/config.h
src/common/config_fwd.h
src/common/lock_mutex.h [new file with mode: 0644]
src/common/lock_policy.h [new file with mode: 0644]

index 37a3f036ef3cc8b7df4c1bee68f6c550d54ea33b..d9ed6fc7b64229c2848692528bf3c66c163b827e 100644 (file)
@@ -102,7 +102,8 @@ namespace ceph::internal {
 template<LockPolicy lp>
 md_config_impl<lp>::md_config_impl(bool is_daemon)
   : is_daemon(is_daemon),
-    cluster("")
+    cluster(""),
+    lock("md_config_t", true, false)
 {
   // Load the compile-time list of Option into
   // a map so that we can resolve keys quickly.
index b483189dd7a968a1f61a73ff59eac10f8526b35f..b6bb31dcd460296009f62cfa670ff9f1ca8d75d4 100644 (file)
@@ -24,7 +24,8 @@
 #include "log/SubsystemMap.h"
 #include "common/options.h"
 #include "common/subsys_types.h"
-#include "config_fwd.h"
+#include "common/config_fwd.h"
+#include "common/lock_mutex.h"
 
 class CephContext;
 
@@ -41,30 +42,6 @@ enum {
 extern const char *ceph_conf_level_name(int level);
 
 namespace ceph::internal {
-// empty helper class except when the template argument is policy_mutex
-template<LockPolicy lp>
-class LockMutex {
-  struct Locker {};
-public:
-  Locker operator()() const {
-    return Locker{};
-  }
-  bool is_locked() const {
-    return true;
-  }
-};
-
-template<>
-class LockMutex<LockPolicy::MUTEX> {
-  mutable Mutex mutex{"md_config_t", true, false};
-public:
-  auto operator()() const {
-    return Mutex::Locker{mutex};
-  }
-  bool is_locked() const {
-    return mutex.is_locked();
-  }
-};
 
 /** This class represents the current Ceph configuration.
  *
index 555a3b97a96a2a18c18a9970ce2d85aeeb88c2d2..ff39a77b9513252b69075982bdaa6c5bde9ab2c0 100644 (file)
@@ -2,13 +2,9 @@
 
 #pragma once
 
-namespace ceph::internal {
-
-enum class LockPolicy {
-  SINGLE,
-  MUTEX,
-};
+#include "lock_policy.h"
 
+namespace ceph::internal {
 template<LockPolicy lp> struct md_config_impl;
 template<LockPolicy lp> class md_config_obs_impl;
 }
diff --git a/src/common/lock_mutex.h b/src/common/lock_mutex.h
new file mode 100644 (file)
index 0000000..40ffa51
--- /dev/null
@@ -0,0 +1,48 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+
+#pragma once
+
+#include "lock_policy.h"
+#include "Mutex.h"
+
+namespace ceph::internal {
+
+template<LockPolicy lp> class LockCond;
+
+// empty helper class except when the template argument is LockPolicy::MUTEX
+template<LockPolicy lp>
+class LockMutex {
+public:
+  template<typename... Args>
+  LockMutex(Args&& ...) {}
+  auto operator()() const {
+    struct Locker {};
+    return Locker{};
+  }
+  bool is_locked() const {
+    return true;
+  }
+};
+
+template<>
+class LockMutex<LockPolicy::MUTEX> {
+public:
+  template<typename... Args>
+  LockMutex(Args&& ...args)
+    : mutex{std::forward<Args>(args)...}
+  {}
+  auto operator()() const {
+    return Mutex::Locker{mutex};
+  }
+  bool is_locked() const {
+    return mutex.is_locked();
+  }
+private:
+  Mutex& get() {
+    return mutex;
+  }
+  mutable Mutex mutex;
+  friend class LockCond<LockPolicy::MUTEX>;
+};
+
+} // namespace ceph::internal
diff --git a/src/common/lock_policy.h b/src/common/lock_policy.h
new file mode 100644 (file)
index 0000000..e710c18
--- /dev/null
@@ -0,0 +1,12 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+
+#pragma once
+
+namespace ceph::internal {
+
+enum class LockPolicy {
+  SINGLE,
+  MUTEX,
+};
+
+}