From: Wolfgang M. M. <wol...@us...> - 2004-08-03 15:26:49
|
Update of /cvsroot/exist/eXist-1.0/src/org/exist/util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8244/src/org/exist/util Modified Files: ReentrantReadWriteLock.java MultiReadReentrantLock.java Lock.java Log Message: Revised collection locking to fix various concurrency errors. It is now the responsibility of the caller to lock/unlock a collection. A collection can be retrieved and locked via the new openCollection() method provided by DBBroker. After reading/modifying the collection, it should be unlocked by calling Collection.release. The local XML:DB implementation and the XMLRPC interface have been changed to reflect the new collection locking rules. Index: Lock.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/util/Lock.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Lock.java 2 Jun 2004 11:34:34 -0000 1.4 --- Lock.java 3 Aug 2004 15:25:57 -0000 1.5 *************** *** 27,33 **** public final static int READ_LOCK = 0; public final static int WRITE_LOCK = 1; /** ! * Attempt to acquire a lock for read. * * @return --- 27,34 ---- public final static int READ_LOCK = 0; public final static int WRITE_LOCK = 1; + public final static int NO_LOCK = -1; /** ! * Acquire a lock for read. * * @return *************** *** 37,41 **** /** ! * Attempt to acquire a lock for read or write. * mode is one of {@link #READ_LOCK} or * {@link #WRITE_LOCK}. --- 38,42 ---- /** ! * Acquire a lock for read or write. * mode is one of {@link #READ_LOCK} or * {@link #WRITE_LOCK}. *************** *** 48,51 **** --- 49,62 ---- /** + * Attempt to acquire a lock for read or write. This method + * will fail immediately if the lock cannot be acquired. + * + * @param mode + * @return + * @throws LockException + */ + public boolean attempt( int mode ); + + /** * Release a lock. This method assumes that the * lock is a read lock. Index: MultiReadReentrantLock.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/util/MultiReadReentrantLock.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** MultiReadReentrantLock.java 8 Jun 2004 08:16:14 -0000 1.2 --- MultiReadReentrantLock.java 3 Aug 2004 15:25:57 -0000 1.3 *************** *** 93,96 **** --- 93,103 ---- } + /* (non-Javadoc) + * @see org.exist.util.Lock#attempt(int) + */ + public boolean attempt(int mode) { + throw new RuntimeException("Not implemented"); + } + /** * Issue a read lock if there is no outstanding write lock or threads Index: ReentrantReadWriteLock.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/util/ReentrantReadWriteLock.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ReentrantReadWriteLock.java 8 Jun 2004 08:16:14 -0000 1.5 --- ReentrantReadWriteLock.java 3 Aug 2004 15:25:57 -0000 1.6 *************** *** 99,102 **** --- 99,122 ---- } + public boolean attempt(int mode) { + Thread caller = Thread.currentThread(); + synchronized (this) { + if (caller == owner_) { + ++holds_; + mode_ = mode; + // System.out.println("thread " + caller.getName() + " acquired lock on " + id_ + + // "; locks held = " + holds_); + return true; + } else if (owner_ == null) { + owner_ = caller; + holds_ = 1; + mode_ = mode; + // System.out.println("thread " + caller.getName() + " acquired lock on " + id_); + return true; + } else { + return false; + } + } + } /* (non-Javadoc) |