X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2FScheduler.java;h=9e939a3d87f7a55c77971268342d403004b4278e;hb=de378041d5ca2aca1a2b5a31ef15ae90a86c977f;hp=95fd6bf321b4395f2bf089b7a52371ef9a4d5739;hpb=6a96430e10e27fc1de5754cb5add705f929dd109;p=org.ibex.core.git diff --git a/src/org/xwt/Scheduler.java b/src/org/xwt/Scheduler.java index 95fd6bf..9e939a3 100644 --- a/src/org/xwt/Scheduler.java +++ b/src/org/xwt/Scheduler.java @@ -1,34 +1,90 @@ -// Copyright 2003 Adam Megacz, see the COPYING file for licensing [GPL] +// Copyright 2004 Adam Megacz, see the COPYING file for licensing [GPL] package org.xwt; import java.util.*; import org.xwt.js.*; import org.xwt.util.*; -// FEATURE: reimplement Watcher /** Implements cooperative multitasking */ public class Scheduler { - private static Scheduler singleton = new Scheduler(); - public static void run() { singleton.do_run(); } + // Public API Exposed to org.xwt ///////////////////////////////////////////////// + + private static Scheduler singleton; + public static interface Task { public abstract void perform() throws Exception; } + public static void add(Task t) { singleton.runnable.append(t); } + public static void init() { if (singleton == null) (singleton = Platform.getScheduler()).run(); } + + private static Task current = null; + + private static volatile boolean rendering = false; + private static volatile boolean again = false; + + /** synchronizd so that we can safely call it from an event-delivery thread, in-context */ + public static void renderAll() { + if (rendering) { again = true; return; } + synchronized(Scheduler.class) { + try { + rendering = true; + do { + // FEATURE: this could be cleaner + again = false; + for(int i=0; i