]> git.proxmox.com Git - ceph.git/blame - ceph/src/mds/LocalLock.h
update sources to 12.2.7
[ceph.git] / ceph / src / mds / LocalLock.h
CommitLineData
7c673cae
FG
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
3/*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
7 *
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.
12 *
13 */
14
15
16#ifndef CEPH_LOCALLOCK_H
17#define CEPH_LOCALLOCK_H
18
19#include "SimpleLock.h"
20
21class LocalLock : public SimpleLock {
22public:
23 client_t last_wrlock_client;
24
25 LocalLock(MDSCacheObject *o, LockType *t) :
26 SimpleLock(o, t) {
27 set_state(LOCK_LOCK); // always.
28 }
29
30 bool is_locallock() const override {
31 return true;
32 }
33
34 bool can_xlock_local() const {
35 return !is_wrlocked() && (get_xlock_by() == MutationRef());
36 }
37
38 bool can_wrlock() const {
39 return !is_xlocked();
40 }
41 void get_wrlock(client_t client) {
42 assert(can_wrlock());
43 SimpleLock::get_wrlock();
44 last_wrlock_client = client;
45 }
46 void put_wrlock() {
47 SimpleLock::put_wrlock();
48 if (get_num_wrlocks() == 0)
49 last_wrlock_client = client_t();
50 }
51 client_t get_last_wrlock_client() const {
52 return last_wrlock_client;
53 }
54
55 void print(ostream& out) const override {
56 out << "(";
57 _print(out);
58 if (last_wrlock_client >= 0)
59 out << " last_client=" << last_wrlock_client;
60 out << ")";
61 }
62};
63
64
65#endif