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.
16 #ifndef CEPH_LOCALLOCK_H
17 #define CEPH_LOCALLOCK_H
19 #include "SimpleLock.h"
21 class LocalLock : public SimpleLock {
23 client_t last_wrlock_client;
25 LocalLock(MDSCacheObject *o, LockType *t) :
27 set_state(LOCK_LOCK); // always.
30 bool is_locallock() const override {
34 bool can_xlock_local() const {
35 return !is_wrlocked() && (get_xlock_by() == MutationRef());
38 bool can_wrlock() const {
41 void get_wrlock(client_t client) {
43 SimpleLock::get_wrlock();
44 last_wrlock_client = client;
47 SimpleLock::put_wrlock();
48 if (get_num_wrlocks() == 0)
49 last_wrlock_client = client_t();
51 client_t get_last_wrlock_client() const {
52 return last_wrlock_client;
55 void print(ostream& out) const override {
58 if (last_wrlock_client >= 0)
59 out << " last_client=" << last_wrlock_client;