Skip to content

Commit

Permalink
2.1: Merged revision 1040090 (JCR-2820)
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/jackrabbit/branches/2.1@1040102 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
jukka committed Nov 29, 2010
1 parent 870bf9c commit 201eb4f
Showing 1 changed file with 8 additions and 6 deletions.
Expand Up @@ -16,6 +16,9 @@
*/
package org.apache.jackrabbit.core.state;

import static org.apache.jackrabbit.core.TransactionContext.getCurrentThreadId;
import static org.apache.jackrabbit.core.TransactionContext.isSameThreadId;

import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
Expand Down Expand Up @@ -52,7 +55,7 @@ public class FineGrainedISMLocking implements ISMLocking {
*/
private WriteLockImpl activeWriter;

private volatile Thread activeWriterThread;
private volatile Object activeWriterId;

private ReadWriteLock writerStateRWLock = new WriterPreferenceReadWriteLock();

Expand All @@ -79,7 +82,7 @@ public class FineGrainedISMLocking implements ISMLocking {
*/
public ReadLock acquireReadLock(ItemId id)
throws InterruptedException {
if (activeWriterThread == Thread.currentThread()) {
if (isSameThreadId(activeWriterId, getCurrentThreadId())) {
// we hold the write lock
readLockMap.addLock(id);
return new ReadLockImpl(id);
Expand Down Expand Up @@ -126,7 +129,7 @@ public WriteLock acquireWriteLock(ChangeLog changeLog)
if (activeWriter == null
&& !readLockMap.hasDependency(changeLog)) {
activeWriter = new WriteLockImpl(changeLog);
activeWriterThread = Thread.currentThread();
activeWriterId = getCurrentThreadId();
return activeWriter;
} else {
signal = new Latch();
Expand Down Expand Up @@ -164,7 +167,7 @@ public void release() {
}
try {
activeWriter = null;
activeWriterThread = null;
activeWriterId = null;
notifyWaitingReaders();
notifyWaitingWriters();
} finally {
Expand All @@ -186,7 +189,6 @@ public ReadLock downgrade() {
}
try {
activeWriter = null;
activeWriterThread = null;
// only notify waiting readers since we still hold a down
// graded lock, which is kind of exclusiv with respect to
// other writers
Expand Down Expand Up @@ -224,7 +226,7 @@ public void release() {
}
try {
readLockMap.removeLock(id);
if (activeWriterThread != Thread.currentThread()) {
if (!isSameThreadId(activeWriterId, getCurrentThreadId())) {
// only notify waiting writers if we do *not* hold a write
// lock at the same time. that would be a waste of cpu time.
notifyWaitingWriters();
Expand Down

0 comments on commit 201eb4f

Please sign in to comment.