X-Git-Url: http://git.megacz.com/?p=org.ibex.core.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fplat%2FPlatform.java;h=389caa4f03c975258b0cd6e543301c1e63b8e549;hp=321a80d319144cd472378e7e2d5ec75707c42fb5;hb=890000a10a0ccdc49f62946bddf1c0b840495a94;hpb=1de73c721bbd73f275ba85de292463cdd8a0fbc0 diff --git a/src/org/ibex/plat/Platform.java b/src/org/ibex/plat/Platform.java index 321a80d..389caa4 100644 --- a/src/org/ibex/plat/Platform.java +++ b/src/org/ibex/plat/Platform.java @@ -293,6 +293,91 @@ public abstract class Platform { return p; } } + + /** Implements cooperative multitasking */ + public static class Scheduler { + + // Public API Exposed to org.ibex ///////////////////////////////////////////////// + + private static Scheduler singleton; + public static void add(Callable t) { Log.debug(Scheduler.class, "scheduling " + t); Scheduler.runnable.append(t); } + public static void init() { if (singleton == null) (singleton = Platform.getScheduler()).run(); } + + private static Callable 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