01: /*
02: * ReadWriteLock.java
03: * :tabSize=8:indentSize=8:noTabs=false:
04: * :folding=explicit:collapseFolds=1:
05: *
06: * Copyright (C) 2001 Peter Graves
07: *
08: * This program is free software; you can redistribute it and/or
09: * modify it under the terms of the GNU General Public License
10: * as published by the Free Software Foundation; either version 2
11: * of the License, or (at your option) any later version.
12: *
13: * This program is distributed in the hope that it will be useful,
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16: * GNU General Public License for more details.
17: *
18: * You should have received a copy of the GNU General Public License
19: * along with this program; if not, write to the Free Software
20: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21: */
22:
23: package org.gjt.sp.util;
24:
25: import java.util.concurrent.locks.ReentrantReadWriteLock;
26:
27: /**
28: * Implements consumer/producer locking scemantics.
29: * @author Peter Graves
30: * @version $Id: ReadWriteLock.java 9230 2007-03-27 23:28:13Z ezust $
31: * The lock tries to be re-entrant when called from the same thread in some
32: * cases.
33: *
34: * The following is ok:
35: * read lock
36: * read lock
37: * read unlock
38: * read unlock
39: *
40: * write lock
41: * read lock
42: * read unlock
43: * write unlock
44: *
45: * The following is not ok:
46: *
47: * read lock
48: * write lock
49: * write unlock
50: * read unlock
51: *
52: * write lock
53: * write lock
54: * write unlock
55: * write unlock
56: *
57: * @deprecated Use java.util.concurrent.locks.ReentrantReadWriteLock which
58: * is available since J2SE 5.0 (1.5). This class was written for J2SE 1.4,
59: * and is still here only for compatibility.
60: */
61: public class ReadWriteLock {
62: //{{{ readLock() method
63: public void readLock() {
64: body.readLock().lock();
65: } //}}}
66:
67: //{{{ readUnlock() method
68: public void readUnlock() {
69: body.readLock().unlock();
70: } //}}}
71:
72: //{{{ writeLock() method
73: public void writeLock() {
74: body.writeLock().lock();
75: } //}}}
76:
77: //{{{ writeUnlock() method
78: public void writeUnlock() {
79: body.writeLock().unlock();
80: } //}}}
81:
82: //{{{ isWriteLocked() method
83: public boolean isWriteLocked() {
84: return body.isWriteLocked();
85: } //}}}
86:
87: //{{{ Private members
88: private final ReentrantReadWriteLock body = new ReentrantReadWriteLock();
89: //}}}
90: }
|