Require a name, like Mutex.
Most callers are passing a C string. This may avoid a std::string
copy?
Signed-off-by: Sage Weil <sage@redhat.com>
l_mutex_last
};
-mutex_debugging_base::mutex_debugging_base(const std::string &n, bool bt) :
- id(-1), backtrace(bt), nlock(0), locked_by(thread::id()) {
- if (n.empty()) {
- uuid_d uu;
- uu.generate_random();
- name = string("Unnamed-Mutex-") + uu.to_string();
- } else {
- name = n;
- }
+mutex_debugging_base::mutex_debugging_base(const std::string &n, bool bt)
+ : name(n), id(-1), backtrace(bt), nlock(0), locked_by(thread::id())
+{
+ if (g_lockdep)
+ _register();
+}
+mutex_debugging_base::mutex_debugging_base(const char *n, bool bt)
+ : name(n), id(-1), backtrace(bt), nlock(0), locked_by(thread::id())
+{
if (g_lockdep)
_register();
}
void _locked(); // just locked
void _will_unlock(); // about to unlock
- mutex_debugging_base(const std::string &n = std::string(), bool bt = false);
+ mutex_debugging_base(const std::string &n, bool bt = false);
+ mutex_debugging_base(const char *n, bool bt = false);
~mutex_debugging_base();
ceph::mono_time before_lock_blocks();
{
private:
pthread_mutex_t m;
-public:
- static constexpr bool recursive = Recursive;
- // Mutex concept is DefaultConstructible
- mutex_debug_impl(const std::string &n = std::string(), bool bt = false)
- : mutex_debugging_base(n, bt) {
+ void _init() {
pthread_mutexattr_t a;
pthread_mutexattr_init(&a);
int r;
r = pthread_mutex_init(&m, &a);
ceph_assert(r == 0);
}
+
+public:
+ static constexpr bool recursive = Recursive;
+
+ // Mutex concept is DefaultConstructible
+ mutex_debug_impl(const std::string &n, bool bt = false)
+ : mutex_debugging_base(n, bt) {
+ _init();
+ }
+ mutex_debug_impl(const char *n, bool bt = false)
+ : mutex_debugging_base(n, bt) {
+ _init();
+ }
+
// Mutex is Destructible
~mutex_debug_impl() {
int r = pthread_mutex_destroy(&m);
template<typename Mutex>
static void test_lock() {
- Mutex m;
+ Mutex m("mutex");
auto ttl = &test_try_lock<Mutex>;
m.lock();
}
TEST(MutexDebug, NotRecursive) {
- ceph::mutex_debug m;
+ ceph::mutex_debug m("foo");
auto ttl = &test_try_lock<mutex_debug>;
ASSERT_NO_THROW(m.lock());
TEST(MutexRecursiveDebug, Recursive) {
- ceph::mutex_recursive_debug m;
+ ceph::mutex_recursive_debug m("m");
auto ttl = &test_try_lock<mutex_recursive_debug>;
ASSERT_NO_THROW(m.lock());