Revision: 3745
          http://vexi.svn.sourceforge.net/vexi/?rev=3745&view=rev
Author:   mkpg2
Date:     2009-11-04 00:29:30 +0000 (Wed, 04 Nov 2009)

Log Message:
-----------
Small changes.

Modified Paths:
--------------
    trunk/core/org.ibex.js/src/org/ibex/js/Scheduler.java
    trunk/core/org.ibex.js/src_dev/org/ibex/js/RunJS.java
    trunk/core/org.vexi.core/src/org/vexi/core/Main.java

Modified: trunk/core/org.ibex.js/src/org/ibex/js/Scheduler.java
===================================================================
--- trunk/core/org.ibex.js/src/org/ibex/js/Scheduler.java       2009-11-04 
00:20:55 UTC (rev 3744)
+++ trunk/core/org.ibex.js/src/org/ibex/js/Scheduler.java       2009-11-04 
00:29:30 UTC (rev 3745)
@@ -40,10 +40,17 @@
         this.quitOnExn = quitOnExn;
     }
     
-    // HACK - Allows Backgound java.lang.threads to make sure the scheduler 
does not finish and
-    // think there is nothing more to do (no more js threads/other events yet)
-    public int forceActive = 0;
-    public void decForceActive() {
+    // REMARK - other java threads may want to keep the scheduler from 
finishing,
+    // as they may schedule work later. This does not apply to background 
threads
+    // started from a paused js thread (e.g. xmlrpc call) as the scheduler 
knows
+    // about these.
+    // REMARK - inc not synchronized. Should not be relied upon, best called 
before
+    // scheduler runs or from a js thread. 
+    private int forceActive = 0;
+    public void incForceActive(){
+       forceActive--;
+    }
+    synchronized public void decForceActive() {
         forceActive--;
         if (forceActive==0) {
             // So that finisher may be run we schedule an empty callable
@@ -405,7 +412,7 @@
     }
 
     final private Basket.Array sleeperThreads = new Basket.Array();
-    final private WakeupThread scheduleWakeUp = new WakeupThread();
+    final WakeupThread scheduleWakeUp = new WakeupThread(); 
     
     /** cause the current (background only) thread to sleep for i ms */
     public void sleep(final int i) throws JSExn {
@@ -435,7 +442,7 @@
 
     /** an internal mechanism for scheduling the wake up of sleeper threads
      * @author Charles Goodwin */
-    final private class WakeupThread extends java.lang.Thread {
+    final class WakeupThread extends java.lang.Thread {
         public WakeupThread() { super("WakeupThread"); start(); }
         public void insert(int i, Callable callback) {
             SleeperCallback t = new SleeperCallback(i, callback);

Modified: trunk/core/org.ibex.js/src_dev/org/ibex/js/RunJS.java
===================================================================
--- trunk/core/org.ibex.js/src_dev/org/ibex/js/RunJS.java       2009-11-04 
00:20:55 UTC (rev 3744)
+++ trunk/core/org.ibex.js/src_dev/org/ibex/js/RunJS.java       2009-11-04 
00:29:30 UTC (rev 3745)
@@ -152,6 +152,14 @@
                return SCHEDULER.runInCurrent((JSFunction) 
export.get(JSU.S(method)),null,args);
        }
        
+       static public boolean finishedCleanly() throws Exception{
+               for(int i=10; i>0; i--){
+                       if(!SCHEDULER.scheduleWakeUp.isAlive()) return true;
+                       java.lang.Thread.sleep(100);
+               }
+               return false;
+       }
+       
        /*
         * TODO start scheduler somewhere(!)
         * 
@@ -294,6 +302,7 @@
                        // INCONSISTENT with vexi obj (tobe changed)
                        if("xmlrpc".equals(key)) return METHOD;
                        if("yield".equals(key)) return METHOD;
+                       if("sleep".equals(key)) return METHOD;
                        if("pause".equals(key)) return METHOD;
                        if("regexp".equals(key)) return METHOD;
                        
@@ -327,7 +336,12 @@
                        return super.get(arg);
                }
                
-               public void put(JS key, JS val) throws JSExn {
+               public void put(JS jskey, JS val) throws JSExn {
+                       String key = JSU.toString(jskey);
+                       if("thread".equals(key)) {
+                               SCHEDULER.runInNew(val,null);
+                               return;
+                       }
                        /*
                        if("bgput".equals(JSU.toString(key))) {
                                action = JSU.toString(val);
@@ -338,11 +352,11 @@
                                }
                                return;
                        }*/   
-                       if("exit".equals(JSU.toString(key))) {
+                       if("exit".equals(key)) {
                                System.exit(JSU.toInt(val));
                                return;
                        }
-                       super.put(key,val);
+                       super.put(jskey,val);
                }
                
                public JS callMethod(JS this_, JS method, JS[] args) throws 
JSExn {
@@ -388,6 +402,9 @@
             if( "xmlrpc".equals(methName)){
                return new XMLRPC(LOG, JSU.toString(args[0]), "");
             }
+            if( "sleep".equals(methName)){
+               SCHEDULER.sleep(JSU.toInt(args[0]));
+            }
             if( "yield".equals(methName)){
                SCHEDULER.sleep(-1);
             }

Modified: trunk/core/org.vexi.core/src/org/vexi/core/Main.java
===================================================================
--- trunk/core/org.vexi.core/src/org/vexi/core/Main.java        2009-11-04 
00:20:55 UTC (rev 3744)
+++ trunk/core/org.vexi.core/src/org/vexi/core/Main.java        2009-11-04 
00:29:30 UTC (rev 3745)
@@ -207,7 +207,7 @@
        }
         
        SCHEDULER = Platform.newScheduler();
-       SCHEDULER.forceActive ++;
+       SCHEDULER.incForceActive();
        SCHEDULER.add(new Callable() {
                        public Object run(Object o) throws Exception {
                                org.vexi.core.Surface.scarImage = 
Picture.load(scar, new Callable() {


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Vexi-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to