Revision: 3698
          http://vexi.svn.sourceforge.net/vexi/?rev=3698&view=rev
Author:   mkpg2
Date:     2009-09-30 01:29:20 +0000 (Wed, 30 Sep 2009)

Log Message:
-----------
Fix. WakeupThread was not properly synchronized.

Modified Paths:
--------------
    trunk/core/org.ibex.js/src/org/ibex/js/Scheduler.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-09-29 
19:38:15 UTC (rev 3697)
+++ trunk/core/org.ibex.js/src/org/ibex/js/Scheduler.java       2009-09-30 
01:29:20 UTC (rev 3698)
@@ -415,24 +415,7 @@
             if (i<0) {
                 add(callback);
             } else {
-                SleeperCallback t = new SleeperCallback(i, callback);
-                synchronized (scheduleWakeUp) {
-                    // store sleeper threads in order of wake up time
-                    for (int j=sleeperThreads.size(); j>=0; j--) {
-                        if (j==0) {
-                            // add as the first thread
-                            sleeperThreads.add(0, t);
-                            // been added at the start so must interrupt the 
wakeup thread
-                            // because it is either waiting or waking up a 
later js thread
-                            scheduleWakeUp.notify();
-                            break;
-                        } else if (t.wakeupms > 
((SleeperCallback)sleeperThreads.get(j-1)).wakeupms) {
-                            // insert at this point
-                            sleeperThreads.add(j, t);
-                            break;
-                        }
-                    }
-                }
+               scheduleWakeUp.insert(i, callback);
             }
         } catch (JSExn e) {
             throw new JSExn("You cannot sleep or yield in the foreground 
thread");
@@ -453,11 +436,32 @@
     /** an internal mechanism for scheduling the wake up of sleeper threads
      * @author Charles Goodwin */
     final private class WakeupThread extends java.lang.Thread {
-        public WakeupThread() { start(); }
-        public void run() {
+        public WakeupThread() { super("WakeupThread"); start(); }
+        public void insert(int i, Callable callback) {
+            SleeperCallback t = new SleeperCallback(i, callback);
+            synchronized (this) {
+                // store sleeper threads in order of wake up time
+                for (int j=sleeperThreads.size(); j>=0; j--) {
+                       if (j==0) {
+                               // add as the first thread
+                        sleeperThreads.add(0, t);
+                        // been added at the start so must interrupt the 
wakeup thread
+                        // because it is either waiting or waking up a later 
js thread
+                        
+                        scheduleWakeUp.notify();
+                        break;
+                    } else if (t.wakeupms > 
((SleeperCallback)sleeperThreads.get(j-1)).wakeupms) {
+                       // insert at this point
+                        sleeperThreads.add(j, t);
+                        break;
+                    }
+                }
+            }
+               }
+               public void run() {
             try {
-                while (true) {
-                    synchronized (this) {
+                synchronized (this) {
+                       while (true) {
                         // nothing to do at this point, await interruption
                         wait();
                         while (sleeperThreads.size()>0) {


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

------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Vexi-svn mailing list
Vexi-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to