1+
2+ /**
3+ * Licensed to the Apache Software Foundation (ASF) under one
4+ * or more contributor license agreements. See the NOTICE file
5+ * distributed with this work for additional information
6+ * regarding copyright ownership. The ASF licenses this file
7+ * to you under the Apache License, Version 2.0 (the
8+ * "License"); you may not use this file except in compliance
9+ * with the License. You may obtain a copy of the License at
10+ *
11+ * http://www.apache.org/licenses/LICENSE-2.0
12+ *
13+ * Unless required by applicable law or agreed to in writing, software
14+ * distributed under the License is distributed on an "AS IS" BASIS,
15+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+ * See the License for the specific language governing permissions and
17+ * limitations under the License.
18+ */
19+
20+ package org .apache .hadoop .hdfs .server .namenode ;
21+
22+ import java .util .concurrent .locks .Lock ;
23+ import java .util .concurrent .locks .ReadWriteLock ;
24+ import java .util .concurrent .locks .ReentrantReadWriteLock ;
25+
26+ import com .google .common .annotations .VisibleForTesting ;
27+
28+ /**
29+ * Mimics a ReentrantReadWriteLock so more sophisticated locking capabilities
30+ * are possible.
31+ */
32+ class FSNamesystemLock implements ReadWriteLock {
33+ @ VisibleForTesting
34+ protected ReentrantReadWriteLock coarseLock ;
35+
36+ FSNamesystemLock (boolean fair ) {
37+ this .coarseLock = new ReentrantReadWriteLock (fair );
38+ }
39+
40+ @ Override
41+ public Lock readLock () {
42+ return coarseLock .readLock ();
43+ }
44+
45+ @ Override
46+ public Lock writeLock () {
47+ return coarseLock .writeLock ();
48+ }
49+
50+ public int getReadHoldCount () {
51+ return coarseLock .getReadHoldCount ();
52+ }
53+
54+ public int getWriteHoldCount () {
55+ return coarseLock .getWriteHoldCount ();
56+ }
57+
58+ public boolean isWriteLockedByCurrentThread () {
59+ return coarseLock .isWriteLockedByCurrentThread ();
60+ }
61+ }
0 commit comments