|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2001 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.mdr.util; import java.util.LinkedList; import java.util.WeakHashMap; /** * * @author Martin Matula * @version */ public class RWMutex { private Thread thread = null; private int counter = 0; private final RWMutex dependent; /** Creates new Mutex */ public RWMutex() { dependent = null; } /** Creates new mutex which will lock the provided dependent mutex for reading. * @param dependent mutex that will be locked by this mutex for reading */ public RWMutex(RWMutex dependent) { this.dependent = dependent; } public synchronized void enter(boolean writer) { Thread thread = Thread.currentThread(); while (counter > 0 && this.thread != thread) { try { this.wait(); } catch (InterruptedException e) { Logger.getDefault().notify(Logger.INFORMATIONAL, e); } } this.thread = thread; counter++; if (dependent != null) dependent.enter(false); } public synchronized void leave() { if (dependent != null) dependent.leave(); counter--; this.notifyAll(); } } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.