]> git.proxmox.com Git - ceph.git/blob - ceph/src/mds/LocalLockC.h
import ceph 16.2.6
[ceph.git] / ceph / src / mds / LocalLockC.h
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
21 class LocalLockC : public SimpleLock {
22 public:
23 LocalLockC(MDSCacheObject *o, LockType *t) :
24 SimpleLock(o, t) {
25 set_state(LOCK_LOCK); // always.
26 }
27
28 bool is_locallock() const override {
29 return true;
30 }
31
32 bool can_xlock_local() const {
33 return !is_wrlocked() && (get_xlock_by() == MutationRef());
34 }
35
36 bool can_wrlock() const {
37 return !is_xlocked();
38 }
39 void get_wrlock(client_t client) {
40 ceph_assert(can_wrlock());
41 SimpleLock::get_wrlock();
42 last_wrlock_client = client;
43 }
44 void put_wrlock() {
45 SimpleLock::put_wrlock();
46 if (get_num_wrlocks() == 0)
47 last_wrlock_client = client_t();
48 }
49 client_t get_last_wrlock_client() const {
50 return last_wrlock_client;
51 }
52
53 void print(std::ostream& out) const override {
54 out << "(";
55 _print(out);
56 if (last_wrlock_client >= 0)
57 out << " last_client=" << last_wrlock_client;
58 out << ")";
59 }
60
61 private:
62 client_t last_wrlock_client;
63 };
64 #endif