From 0df63f38249cbbc584d3a130773680c309fb1f71 Mon Sep 17 00:00:00 2001 From: Antti Villberg Date: Thu, 9 Jan 2020 13:59:08 +0200 Subject: [PATCH] MainProgram polls nanoTime too often gitlab #440 Change-Id: I9d6b1514907682b990ae21588ced70b35f5ed6f5 --- .../src/org/simantics/acorn/MainProgram.java | 6 ++---- .../src/org/simantics/acorn/OperationQueue.java | 6 ++++-- 2 files changed, 6 insertions(+), 6 deletions(-) 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; } -- 2.47.1