NBMDRepositoryImpl.shutdown method fixed to wait till all started transactions are finished (the bug caused deadlocks on IDE shutdown)
1.1 --- a/mdr/src/org/netbeans/mdr/NBMDRepositoryImpl.java Tue Jul 13 13:52:09 2004 +0000
1.2 +++ b/mdr/src/org/netbeans/mdr/NBMDRepositoryImpl.java Tue Jul 13 19:44:04 2004 +0000
1.3 @@ -367,6 +367,14 @@
1.4 public synchronized void shutdown() {
1.5 if (mdrStorage != null) {
1.6 try {
1.7 + TransactionMutex mutex = mdrStorage.getRepositoryMutex();
1.8 + while (mutex.isLocked()) {
1.9 + try {
1.10 + this.wait(100);
1.11 + } catch (InterruptedException e) {
1.12 + Logger.getDefault().notify(Logger.INFORMATIONAL, e);
1.13 + }
1.14 + }
1.15 mdrStorage.shutDown();
1.16 } catch (StorageException e) {
1.17 throw (DebugException) Logger.getDefault().annotate(new DebugException(), e);
2.1 --- a/mdr/src/org/netbeans/mdr/util/MultipleReadersMutex.java Tue Jul 13 13:52:09 2004 +0000
2.2 +++ b/mdr/src/org/netbeans/mdr/util/MultipleReadersMutex.java Tue Jul 13 19:44:04 2004 +0000
2.3 @@ -36,6 +36,7 @@
2.4
2.5 /** Counter of locks in the single writer thread. */
2.6 private volatile int counter = 0;
2.7 + private int waitCount = 0;
2.8
2.9 /** Maps reader threads to the counter of read locks acquired by them, i.e.
2.10 * to the counter of nested read transactions currently in process in
2.11 @@ -74,6 +75,10 @@
2.12 public boolean pendingChanges() {
2.13 return counter > 0;
2.14 }
2.15 +
2.16 + public synchronized boolean isLocked() {
2.17 + return waitCount > 0 || counter > 0 || !readers.isEmpty();
2.18 + }
2.19
2.20 /* -------------------------------------------------------------------- */
2.21 /* -- transaction lock methods ---------------------------------------- */
2.22 @@ -97,24 +102,29 @@
2.23 synchronized (this) {
2.24 Counter rCount = (Counter) readers.get(thread);
2.25 isMutator = mutators.contains(thread);
2.26 - while ((counter > 0 && writer != thread) ||
2.27 - (writeAccess && (!mutators.containsAll(readers.keySet())))) {
2.28 - // (writeAccess && (((size = readers.size()) > 1) ||
2.29 - // (size == 1 && readers.get(thread) == null)))) {
2.30 + waitCount++;
2.31 + try {
2.32 + while ((counter > 0 && writer != thread) ||
2.33 + (writeAccess && (!mutators.containsAll(readers.keySet())))) {
2.34 + // (writeAccess && (((size = readers.size()) > 1) ||
2.35 + // (size == 1 && readers.get(thread) == null)))) {
2.36
2.37 - // reader cannot enter a write transaction as it would not be possible to
2.38 - // prevent deadlocks (when two readers decide to enter write, they would
2.39 - // lock each other)
2.40 - if ((rCount != null) && !isMutator) {
2.41 - System.err.println("Writable lock nested in read-only lock.");
2.42 - Thread.dumpStack();
2.43 - throw new DebugException("Writable lock nested in read-only lock.");
2.44 + // reader cannot enter a write transaction as it would not be possible to
2.45 + // prevent deadlocks (when two readers decide to enter write, they would
2.46 + // lock each other)
2.47 + if ((rCount != null) && !isMutator) {
2.48 + System.err.println("Writable lock nested in read-only lock.");
2.49 + Thread.dumpStack();
2.50 + throw new DebugException("Writable lock nested in read-only lock.");
2.51 + }
2.52 + try {
2.53 + this.wait();
2.54 + } catch (InterruptedException e) {
2.55 + Logger.getDefault().notify(Logger.INFORMATIONAL, e);
2.56 + }
2.57 }
2.58 - try {
2.59 - this.wait();
2.60 - } catch (InterruptedException e) {
2.61 - Logger.getDefault().notify(Logger.INFORMATIONAL, e);
2.62 - }
2.63 + } finally {
2.64 + waitCount--;
2.65 }
2.66 if (writeAccess || counter > 0) {
2.67 if (counter == 0) {
3.1 --- a/mdr/src/org/netbeans/mdr/util/TransactionMutex.java Tue Jul 13 13:52:09 2004 +0000
3.2 +++ b/mdr/src/org/netbeans/mdr/util/TransactionMutex.java Tue Jul 13 19:44:04 2004 +0000
3.3 @@ -42,6 +42,8 @@
3.4 this.repository = (NBMDRepositoryImpl) repository;
3.5 }
3.6
3.7 + public abstract boolean isLocked();
3.8 +
3.9 public abstract boolean willFail();
3.10
3.11 public abstract boolean pendingChanges();