Stream->Fountain, move Scheduler to Platform, HashMap->Hash
[org.ibex.core.git] / src / org / ibex / core / Scheduler.java
diff --git a/src/org/ibex/core/Scheduler.java b/src/org/ibex/core/Scheduler.java
deleted file mode 100644 (file)
index 8fdb506..0000000
+++ /dev/null
@@ -1,97 +0,0 @@
-// Copyright 2000-2005 the Contributors, as shown in the revision logs.
-// Licensed under the GNU General Public License version 2 ("the License").
-// You may not use this file except in compliance with the License.
-
-package org.ibex.core;
-
-import java.io.IOException;
-
-import org.ibex.js.*;
-import org.ibex.util.*;
-import org.ibex.graphics.*;
-import org.ibex.plat.*;
-
-/** Implements cooperative multitasking */
-public 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<Surface.allSurfaces.size(); i++) {
-                        Surface s = ((Surface)Surface.allSurfaces.elementAt(i));
-                        do { s.render(); } while(s.abort);
-                    }
-                } while(again);
-            } finally {
-                rendering = false;
-            }
-        }
-    }
-
-    
-
-    // API which must be supported by subclasses /////////////////////////////////////
-
-    /**
-     *  SCHEDULER INVARIANT: all scheduler implementations MUST invoke
-     *  Surface.renderAll() after performing a Callable if no tasks remain
-     *  in the queue.  A scheduler may choose to invoke
-     *  Surface.renderAll() more often than that if it so chooses.
-     */
-    public void run() { defaultRun(); }
-    public Scheduler() { }
-
-
-    // Default Implementation //////////////////////////////////////////////////////
-
-    protected static Queue runnable = new Queue(50);
-    public void defaultRun() {
-        while(true) {
-            current = (Callable)runnable.remove(true);
-            try {
-                // FIXME hideous
-                synchronized(this) {
-                    for(int i=0; i<Surface.allSurfaces.size(); i++) {
-                        Surface s = (Surface)Surface.allSurfaces.elementAt(i);
-                        if (current instanceof JS) {
-                            s._mousex = Integer.MAX_VALUE;
-                            s._mousey = Integer.MAX_VALUE;
-                        } else {
-                            s._mousex = s.mousex;
-                            s._mousey = s.mousey;
-                        }
-                    }
-                    Log.debug(Scheduler.class, "performing " + current);
-                    current.run(null);
-                }
-                renderAll();
-            } catch (JSExn e) {
-                Log.info(Scheduler.class, "a JavaScript thread spawned with ibex.thread() threw an exception:");
-                Log.info(Scheduler.class,e);
-            } catch (Exception e) {
-                Log.info(Scheduler.class, "a Callable threw an exception which was caught by the scheduler:");
-                Log.info(Scheduler.class, e);
-            } catch (Throwable t) {
-                t.printStackTrace();
-            }
-            // if an Error is thrown it will cause the engine to quit
-        }
-    }
-}