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/assert.h"
20 #include "common/ceph_context.h"
29 l_mutex_first = 999082,
40 bool backtrace; // gather backtrace on lock acquisition
48 // don't allow copying.
49 void operator=(const Mutex &M);
50 Mutex(const Mutex &M);
53 id = lockdep_register(name.c_str());
55 void _will_lock() { // about to lock
56 id = lockdep_will_lock(name.c_str(), id, backtrace);
58 void _locked() { // just locked
59 id = lockdep_locked(name.c_str(), id, backtrace);
61 void _will_unlock() { // about to unlock
62 id = lockdep_will_unlock(name.c_str(), id);
66 Mutex(const std::string &n, bool r = false, bool ld=true, bool bt=false,
67 CephContext *cct = 0);
69 bool is_locked() const {
72 bool is_locked_by_me() const {
73 return nlock > 0 && locked_by == pthread_self();
77 int r = pthread_mutex_trylock(&_m);
79 if (lockdep && g_lockdep) _locked();
85 void Lock(bool no_lockdep=false);
90 locked_by = pthread_self();
99 assert(locked_by == pthread_self());
114 explicit Locker(Mutex& m) : mutex(m) {