diff options
author | Rich Hickey <richhickey@gmail.com> | 2007-12-11 11:40:27 +0000 |
---|---|---|
committer | Rich Hickey <richhickey@gmail.com> | 2007-12-11 11:40:27 +0000 |
commit | b41c0d9f7eefbe8541adf68e43f2fcd365466812 (patch) | |
tree | 9473da9bc04e532f975aa6c67de7aa8a6c4f9979 /src | |
parent | b714638884d9b62c7b91b14a374b6988fb3e882d (diff) |
interim checkin
Diffstat (limited to 'src')
-rw-r--r-- | src/jvm/clojure/lang/Agent.java | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/jvm/clojure/lang/Agent.java b/src/jvm/clojure/lang/Agent.java index b8d001f7..a02b8fc4 100644 --- a/src/jvm/clojure/lang/Agent.java +++ b/src/jvm/clojure/lang/Agent.java @@ -18,7 +18,8 @@ import java.util.concurrent.*; public class Agent implements IRef{ volatile Object state; -final Queue q = new LinkedList(); +//final Queue q = new LinkedList(); +IPersistentStack q = PersistentQueue.EMPTY; boolean busy = false; volatile ISeq errors = null; @@ -67,17 +68,23 @@ static class Action implements Runnable{ } } + Runnable exec = null; synchronized(agent) { - if(!agent.q.isEmpty()) + if(agent.q.count() > 0) +// if(!agent.q.isEmpty()) { - executor.execute((Runnable) agent.q.remove()); +// exec = (Runnable) agent.q.remove(); + exec = (Runnable) agent.q.peek(); + agent.q = agent.q.pop(); } else { agent.busy = false; } } + if(exec != null) + executor.execute(exec); nested.set(null); } @@ -135,16 +142,20 @@ public Object dispatch(IFn fn, ISeq args) throws Exception{ } void enqueue(Action action){ + boolean exec = false; synchronized(this) { if(busy) - q.add(action); + // q.add(action); + q = (IPersistentStack) q.cons(action); else { busy = true; - executor.execute(action); + exec = true; } } + if(exec) + executor.execute(action); } } |