2003/12/27 01:03:53
[org.ibex.core.git] / src / org / xwt / Scheduler.java
index ce59d1e..d61ad55 100644 (file)
@@ -26,6 +26,16 @@ public class Scheduler {
     private static Task current = null;
     public static Task current() { return current; }
 
+    /** synchronizd so that we can safely call it from an event-delivery thread, in-context */
+    public static synchronized void renderAll() {
+        for(int i=0; i<Surface.allSurfaces.size(); i++) {
+            Surface s = ((Surface)Surface.allSurfaces.elementAt(i));
+            do { s.render(); } while(s.abort);
+        }
+    }
+
+    
+
     // API which must be supported by subclasses /////////////////////////////////////
 
     /**
@@ -45,18 +55,20 @@ public class Scheduler {
         while(true) {
             current = (Task)runnable.remove(true);
             try {
-                for(int i=0; i<Surface.allSurfaces.size(); i++) {
-                    Surface s = (Surface)Surface.allSurfaces.elementAt(i);
-                    if (current instanceof JSFunction) {
-                        s._mousex = Integer.MAX_VALUE;
-                        s._mousey = Integer.MAX_VALUE;
-                    } else {
-                        s._mousex = s.mousex;
-                        s._mousey = s.mousey;
+                synchronized(this) {
+                    for(int i=0; i<Surface.allSurfaces.size(); i++) {
+                        Surface s = (Surface)Surface.allSurfaces.elementAt(i);
+                        if (current instanceof JSFunction) {
+                            s._mousex = Integer.MAX_VALUE;
+                            s._mousey = Integer.MAX_VALUE;
+                        } else {
+                            s._mousex = s.mousex;
+                            s._mousey = s.mousey;
+                        }
                     }
+                    current.perform();
                 }
-                current.perform();
-                if (runnable.size() == 0 && Surface.needRender) Surface.renderAll.perform();
+                renderAll();
             } catch (JSExn e) {
                 Log.log(Scheduler.class, "a JavaScript thread spawned with xwt.thread() threw an exception:");
                 Log.log(Scheduler.class, e);