summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRich Hickey <richhickey@gmail.com>2007-07-29 19:03:50 +0000
committerRich Hickey <richhickey@gmail.com>2007-07-29 19:03:50 +0000
commitd9acdc7608ed556984ca37d747ec4e5879e378f0 (patch)
tree0b692b5a515cb4f9ecafa1578206716b6c5762b6
parente9aa32282a2b428d12b6409bf4c84ebe7423d16f (diff)
older trans wins on lock conflict
-rw-r--r--src/jvm/clojure/lang/LockingTransaction.java59
1 files changed, 30 insertions, 29 deletions
diff --git a/src/jvm/clojure/lang/LockingTransaction.java b/src/jvm/clojure/lang/LockingTransaction.java
index 21074951..b9ea39c0 100644
--- a/src/jvm/clojure/lang/LockingTransaction.java
+++ b/src/jvm/clojure/lang/LockingTransaction.java
@@ -94,34 +94,31 @@ Object lock(Ref ref) throws Exception{
try
{
ref.lock.writeLock().lock();
+ if(ref.tvals != null && ref.tvals.point > readPoint)
+ throw retryex;
Info refinfo = ref.tinfo;
- //write lock conflict?
+ //write lock conflict
if(refinfo != null && refinfo != info && refinfo.running())
{
+ boolean barged = false;
//if this transaction is older, and could continue if it got the lock,
// try to abort the other
- if(info.startPoint < refinfo.startPoint
- && (ref.tvals == null || ref.tvals.point <= readPoint)
- && refinfo.status.compareAndSet(RUNNING, KILLED))
- {
- ref.tinfo = info;
- return ref.tvals == null ? null : ref.tvals.val;
- }
- ref.lock.writeLock().unlock();
- unlocked = true;
- //stop prior to blocking
- stop(RETRY);
- synchronized(refinfo)
+ if(info.startPoint < refinfo.startPoint)
+ barged = refinfo.status.compareAndSet(RUNNING, KILLED);
+ if(!barged)
{
- if(refinfo.running())
- refinfo.wait(LOCK_WAIT_MSECS);
+ ref.lock.writeLock().unlock();
+ unlocked = true;
+ //stop prior to blocking
+ stop(RETRY);
+ synchronized(refinfo)
+ {
+ if(refinfo.running())
+ refinfo.wait(LOCK_WAIT_MSECS);
+ }
+ throw retryex;
}
- throw retryex;
- }
- if(ref.tvals != null && ref.tvals.point > readPoint)
- {
- throw retryex;
}
ref.tinfo = info;
return ref.tvals == null ? null : ref.tvals.val;
@@ -242,7 +239,8 @@ Object run(IFn fn) throws Exception{
Object doGet(Ref ref) throws Exception{
- if(info.running())
+ if(//true ||
+ info.running())
{
if(vals.containsKey(ref))
return vals.get(ref);
@@ -262,15 +260,16 @@ Object doGet(Ref ref) throws Exception{
ref.lock.readLock().unlock();
}
//no version of val precedes the read point
- throw retryex;//new RetryException();
+ throw retryex;
}
else
- throw retryex;//new RetryException();
+ throw retryex;
}
Object doSet(Ref ref, Object val) throws Exception{
- if(info.running())
+ if(//true ||
+ info.running())
{
if(commutes.containsKey(ref))
throw new IllegalStateException("Can't set after commute");
@@ -283,18 +282,20 @@ Object doSet(Ref ref, Object val) throws Exception{
return val;
}
else
- throw retryex;//new RetryException();
+ throw retryex;
}
void doTouch(Ref ref) throws Exception{
- if(info.running())
+ if(//true ||
+ info.running())
lock(ref);
else
- throw retryex;//new RetryException();
+ throw retryex;
}
Object doCommute(Ref ref, IFn fn) throws Exception{
- if(info.running())
+ if(//true ||
+ info.running())
{
if(!vals.containsKey(ref))
{
@@ -319,7 +320,7 @@ Object doCommute(Ref ref, IFn fn) throws Exception{
return ret;
}
else
- throw retryex;//new RetryException();
+ throw retryex;
}