mirror of
https://github.com/apache/lucene.git
synced 2025-02-14 05:55:26 +00:00
LUCENE-3462: Release lock in DocumentsWriterPerThreadPool if new state has been deactivated during close.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1177941 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d514a4ac75
commit
d607980a5a
@ -186,13 +186,41 @@ public abstract class DocumentsWriterPerThreadPool {
|
||||
if (numThreadStatesActive < perThreads.length) {
|
||||
final ThreadState threadState = perThreads[numThreadStatesActive];
|
||||
threadState.lock(); // lock so nobody else will get this ThreadState
|
||||
numThreadStatesActive++; // increment will publish the ThreadState
|
||||
threadState.perThread.initialize();
|
||||
return threadState;
|
||||
boolean unlock = true;
|
||||
try {
|
||||
if (threadState.isActive()) {
|
||||
// unreleased thread states are deactivated during DW#close()
|
||||
numThreadStatesActive++; // increment will publish the ThreadState
|
||||
assert threadState.perThread != null;
|
||||
threadState.perThread.initialize();
|
||||
unlock = false;
|
||||
return threadState;
|
||||
}
|
||||
// unlock since the threadstate is not active anymore - we are closed!
|
||||
assert assertUnreleasedThreadStatesInactive();
|
||||
return null;
|
||||
} finally {
|
||||
if (unlock) {
|
||||
// in any case make sure we unlock if we fail
|
||||
threadState.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private synchronized boolean assertUnreleasedThreadStatesInactive() {
|
||||
for (int i = numThreadStatesActive; i < perThreads.length; i++) {
|
||||
assert perThreads[i].tryLock() : "unreleased threadstate should not be locked";
|
||||
try {
|
||||
assert !perThreads[i].isActive() : "expected unreleased thread state to be inactive";
|
||||
} finally {
|
||||
perThreads[i].unlock();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deactivate all unreleased threadstates
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user