]>
git.proxmox.com Git - ceph.git/blob - ceph/src/common/Mutex.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
18 #include "include/ceph_assert.h"
33 bool backtrace
; // gather backtrace on lock acquisition
39 // don't allow copying.
40 void operator=(const Mutex
&M
);
41 Mutex(const Mutex
&M
);
44 id
= lockdep_register(name
.c_str());
46 void _will_lock() { // about to lock
47 id
= lockdep_will_lock(name
.c_str(), id
, backtrace
, recursive
);
49 void _locked() { // just locked
50 id
= lockdep_locked(name
.c_str(), id
, backtrace
);
52 void _will_unlock() { // about to unlock
53 id
= lockdep_will_unlock(name
.c_str(), id
);
57 Mutex(const std::string
&n
, bool r
= false, bool ld
=true, bool bt
=false);
59 bool is_locked() const {
62 bool is_locked_by_me() const {
63 return nlock
> 0 && locked_by
== pthread_self();
70 int r
= pthread_mutex_trylock(&_m
);
72 if (lockdep
&& g_lockdep
) _locked();
78 void Lock(bool no_lockdep
=false) {
81 void lock(bool no_lockdep
=false);
85 ceph_assert(nlock
== 0);
86 locked_by
= pthread_self();
92 ceph_assert(nlock
> 0);
95 ceph_assert(locked_by
== pthread_self());
97 ceph_assert(nlock
== 0);
109 typedef std::lock_guard
<Mutex
> Locker
;