Revision: 4769
          http://sourceforge.net/p/vexi/code/4769
Author:   mkpg2
Date:     2015-02-26 18:24:45 +0000 (Thu, 26 Feb 2015)
Log Message:
-----------
Make Thread extendable.

Modified Paths:
--------------
    branches/vexi3/org.vexi-library.js/src/main/java/org/ibex/js/Scheduler.java

Modified: 
branches/vexi3/org.vexi-library.js/src/main/java/org/ibex/js/Scheduler.java
===================================================================
--- branches/vexi3/org.vexi-library.js/src/main/java/org/ibex/js/Scheduler.java 
2015-02-26 04:19:15 UTC (rev 4768)
+++ branches/vexi3/org.vexi-library.js/src/main/java/org/ibex/js/Scheduler.java 
2015-02-26 18:24:45 UTC (rev 4769)
@@ -165,14 +165,21 @@
         jsthread = t;
     }
     
+    
+    protected Thread newThread(Scheduler faction, String name, JS f){ return 
newThread(faction, name, f, false, null); }
+    protected Thread newThread(Scheduler faction, String type, JS f, boolean 
pauseable, Callable<Object,JS> callback)  {
+       return new Thread(faction, type, f, pauseable, callback);
+    }    
+    
+    
     public void runInNew(JS function) throws JSExn { runInNew(function, null, 
null); }
     public void runInNew(JS function, JS[] args, Callable<Object, JS> 
callback) throws JSExn {
-       Thread thread = new Thread(this, "background", function, true, 
callback); 
+       Thread thread = newThread(this, "background", function, true, 
callback); 
                thread.currentInterpreter = new Interpreter(thread, 
(JSFunction)function, true, args);
        add(thread);
     }
     public void runInNew(Trap trap, JS trapname, JS put, Callable<Object, JS> 
callback) throws JSExn {
-       Thread thread = new Thread(this, "background/wtrap", trap.function(), 
true, callback); 
+       Thread thread = newThread(this, "background/wtrap", trap.function(), 
true, callback); 
        TrapMarker marker = new TrapMarker(trap, put);
        thread.currentInterpreter = new Interpreter(thread, marker, trapname);  
        
        add(thread);
@@ -191,7 +198,7 @@
         // REMARK - isFirst <-> old == null?
         boolean isFirst = jsthread==null; 
         if (isFirst) {
-            setJSThread(new Thread(this, "current/trap", trapf));
+            setJSThread(newThread(this, "current/trap", trapf));
         }
         Interpreter old = jsthread.currentInterpreter;
         jsthread.currentInterpreter = new Interpreter(jsthread, t, null, 
false, null);
@@ -225,7 +232,7 @@
     /** Execute write traps, part 1 */
     public JS runBeforePut(Trap t, JS val, JS trapname) throws JSExn {
         if (jsthread==null) {
-            setJSThread(new Thread(this, "current/trap/wpause", t.function()));
+            setJSThread(newThread(this, "current/trap/wpause", t.function()));
         }
         Interpreter I = new Interpreter(jsthread, t, val, true, trapname);
         // REMARK - this thread is unpausable, so setting this static variable
@@ -281,7 +288,7 @@
     /** Execute read traps, part 1 */
     public JS runBeforeGet(Trap t, JS trapname) throws JSExn {
         if (jsthread==null) {
-            setJSThread(new Thread(this, "current/trap/rpause", t.function()));
+            setJSThread(newThread(this, "current/trap/rpause", t.function()));
         }
         Interpreter I = new Interpreter(jsthread, t, null, true, trapname);
         // REMARK - this thread is unpausable, so setting this static variable
@@ -319,7 +326,7 @@
         boolean isFirst = jsthread==null; 
         // FEATURE - reuse the thread object
         if (isFirst) {
-            setJSThread(new Thread(this, "current", function));
+            setJSThread(newThread(this, "current", function));
         }
         Interpreter old = jsthread.currentInterpreter;
         // Always false. Restarting paused nested Interpreters not supported.
@@ -343,7 +350,7 @@
             throw new JSExn("Something a miss"); 
         }
         // FEATURE - reuse the thread object
-        setJSThread(new Thread(this, "non-js", null));
+        setJSThread(newThread(this, "non-js", null));
         // REMARK - This interpreter is just used for its stack for
         // recording non-JS call entries (Box.apply) for backtracing later
         jsthread.currentInterpreter = new Interpreter(jsthread);
@@ -472,8 +479,7 @@
                throw (JSExn)ret;
        }else{
                throw new JSExn((Throwable)ret);
-       }
-    
+       }  
     }
        
     public void scheduleJustTriggerTraps(final JS.Obj obj, final JS key, final 
JS value) {

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


------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Vexi-svn mailing list
Vexi-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to