From: Antti Villberg Date: Thu, 9 Jan 2020 11:59:08 +0000 (+0200) Subject: MainProgram polls nanoTime too often X-Git-Tag: v1.43.0~136^2~9 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=0df63f38249cbbc584d3a130773680c309fb1f71;p=simantics%2Fplatform.git MainProgram polls nanoTime too often gitlab #440 Change-Id: I9d6b1514907682b990ae21588ced70b35f5ed6f5 --- diff --git a/bundles/org.simantics.acorn/src/org/simantics/acorn/MainProgram.java b/bundles/org.simantics.acorn/src/org/simantics/acorn/MainProgram.java index ec4d56c21..1e4b5cbac 100644 --- a/bundles/org.simantics.acorn/src/org/simantics/acorn/MainProgram.java +++ b/bundles/org.simantics.acorn/src/org/simantics/acorn/MainProgram.java @@ -102,17 +102,15 @@ public class MainProgram implements Runnable, Closeable { if(updates.isEmpty()) { - long start = System.nanoTime(); - - operationQueue.waitFor(); + long duration = operationQueue.waitFor(); if (!alive) break main; - long duration = System.nanoTime()-start; if(duration > 4000000000L) { checkIdle(); } + } // long sss = System.nanoTime(); diff --git a/bundles/org.simantics.acorn/src/org/simantics/acorn/OperationQueue.java b/bundles/org.simantics.acorn/src/org/simantics/acorn/OperationQueue.java index 7a9d8aba2..a85aa8829 100644 --- a/bundles/org.simantics.acorn/src/org/simantics/acorn/OperationQueue.java +++ b/bundles/org.simantics.acorn/src/org/simantics/acorn/OperationQueue.java @@ -157,18 +157,20 @@ class OperationQueue { * Wake up when new operations are scheduled or the last operation is committed * Called by MainProgram thread */ - synchronized void waitFor() { + synchronized long waitFor() { mainProgram.assertMainProgramThread(); // One last check within the monitor - if(!operations.isEmpty() || !tasks.isEmpty()) return; + if(!operations.isEmpty() || !tasks.isEmpty()) return 0; + long start = System.nanoTime(); try { wait(5000); } catch (InterruptedException e) { LOGGER.error("Unexpected interruption", e); } + return System.nanoTime() - start; }