X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.db.impl%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fimpl%2Fquery%2FQueryProcessor.java;h=65b277e6c8d2985410b82e12ce4edca3f1fea09d;hp=9c60691fad7a0a850228997e85ffb47168ca1aae;hb=277b1c7fb3fdd8effb4bf2b447358d0e4ef0e302;hpb=4aba159170fc72d39c2f930ea224aa71f4cdc2e7 diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryProcessor.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryProcessor.java index 9c60691fa..65b277e6c 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryProcessor.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryProcessor.java @@ -171,23 +171,25 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap public void close() { } - SessionTask getOwnTask(int thread) { + SessionTask getOwnTask(ReadGraphImpl impl) { + Set ancestors = impl.ancestorSet(); synchronized(querySupportLock) { int index = 0; while(index < freeScheduling.size()) { SessionTask task = freeScheduling.get(index); - if(task.thread == thread && !task.systemCall) + if(task.hasCommonParent(ancestors)) { return freeScheduling.remove(index); + } index++; } } return null; } - - public boolean performPending(int thread) { - SessionTask task = getOwnTask(thread); + + public boolean performPending(ReadGraphImpl graph) { + SessionTask task = getOwnTask(graph); if(task != null) { - task.run(thread); + task.run(QueryProcessor.thread.get()); return true; } else { return false; @@ -200,10 +202,10 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap final public void schedule(SessionTask request) { - int performer = request.thread; + //int performer = request.thread; - if(DebugPolicy.SCHEDULE) - System.out.println("schedule " + request + " " + " -> " + performer); +// if(DebugPolicy.SCHEDULE) +// System.out.println("schedule " + request + " " + " -> " + performer); //assert(performer >= 0); @@ -256,34 +258,29 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap final int THREADS; final public int THREAD_MASK; - - final public static ThreadGroup QueryThreadGroup = new ThreadGroup("Query Thread Group"); + + final public static ThreadGroup QueryThreadGroup = new ThreadGroup("Query Thread Group"); public static abstract class SessionTask { - final public int thread; - final public boolean systemCall; -// final public int syncCaller; - //final public Object object; + public final ReadGraphImpl graph; + private Set ancestors; - public SessionTask(boolean systemCall) { - this.thread = QueryProcessor.thread.get(); - this.systemCall = systemCall; -// this.syncCaller = -1; - //this.object = object; + public SessionTask(ReadGraphImpl graph) { + this.graph = graph; } -// public SessionTask(Object object, int syncCaller) { -// this.thread = QueryProcessor.thread.get(); -// this.syncCaller = syncCaller; -// this.object = object; -// } + public boolean hasCommonParent(Set otherAncestors) { + if(graph == null) return false; + if(ancestors == null) ancestors = graph.ancestorSet(); + return !Collections.disjoint(ancestors, otherAncestors); + } public abstract void run(int thread); @Override public String toString() { - return "SessionTask[" + super.toString() + "]"; + return "SessionTask[" + graph.parent + "]"; } } @@ -294,7 +291,7 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap final public DataContainer throwable; public SessionRead(DataContainer throwable, Semaphore notify) { - super(true); + super(null); this.throwable = throwable; this.notify = notify; } @@ -1593,7 +1590,7 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap entry.prepareRecompute(querySupport); - ReadGraphImpl parentGraph = graph.withParent(entry); + ReadGraphImpl parentGraph = graph.forRecompute(entry); query.recompute(parentGraph); @@ -1765,6 +1762,7 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap } else { // If not changed, keep the old value immediate.setResult(oldValue); + immediate.setReady(); listenersUnknown = true; }