From b5763ffcb02bd26f03515e565afb0bf087a44666 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Wed, 27 Jun 2018 15:36:29 +0800 Subject: [PATCH] common/config: extract LockMutex and LockPolicy out Signed-off-by: Kefu Chai --- src/common/config.cc | 3 ++- src/common/config.h | 27 ++-------------------- src/common/config_fwd.h | 8 ++----- src/common/lock_mutex.h | 48 ++++++++++++++++++++++++++++++++++++++++ src/common/lock_policy.h | 12 ++++++++++ 5 files changed, 66 insertions(+), 32 deletions(-) create mode 100644 src/common/lock_mutex.h create mode 100644 src/common/lock_policy.h diff --git a/src/common/config.cc b/src/common/config.cc index 37a3f036ef3cc..d9ed6fc7b6422 100644 --- a/src/common/config.cc +++ b/src/common/config.cc @@ -102,7 +102,8 @@ namespace ceph::internal { template md_config_impl::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. diff --git a/src/common/config.h b/src/common/config.h index b483189dd7a96..b6bb31dcd4602 100644 --- a/src/common/config.h +++ b/src/common/config.h @@ -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 -class LockMutex { - struct Locker {}; -public: - Locker operator()() const { - return Locker{}; - } - bool is_locked() const { - return true; - } -}; - -template<> -class LockMutex { - 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. * diff --git a/src/common/config_fwd.h b/src/common/config_fwd.h index 555a3b97a96a2..ff39a77b95132 100644 --- a/src/common/config_fwd.h +++ b/src/common/config_fwd.h @@ -2,13 +2,9 @@ #pragma once -namespace ceph::internal { - -enum class LockPolicy { - SINGLE, - MUTEX, -}; +#include "lock_policy.h" +namespace ceph::internal { template struct md_config_impl; template class md_config_obs_impl; } diff --git a/src/common/lock_mutex.h b/src/common/lock_mutex.h new file mode 100644 index 0000000000000..40ffa51490f2b --- /dev/null +++ b/src/common/lock_mutex.h @@ -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 class LockCond; + +// empty helper class except when the template argument is LockPolicy::MUTEX +template +class LockMutex { +public: + template + LockMutex(Args&& ...) {} + auto operator()() const { + struct Locker {}; + return Locker{}; + } + bool is_locked() const { + return true; + } +}; + +template<> +class LockMutex { +public: + template + LockMutex(Args&& ...args) + : mutex{std::forward(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; +}; + +} // namespace ceph::internal diff --git a/src/common/lock_policy.h b/src/common/lock_policy.h new file mode 100644 index 0000000000000..e710c18e9a861 --- /dev/null +++ b/src/common/lock_policy.h @@ -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, +}; + +} -- 2.39.5