Author: miguel
Date: 2007-01-13 16:37:15 -0500 (Sat, 13 Jan 2007)
New Revision: 70965

Modified:
   trunk/olive/class/WindowsBase/ChangeLog
   trunk/olive/class/WindowsBase/System.Windows.Threading/Dispatcher.cs
Log:
2007-01-13  Miguel de Icaza  <[EMAIL PROTECTED]>

        * System.Windows.Threading/Dispatcher.cs: Initially I thought this
        was a stroke of genius.   Looking at the actual results, it does
        not seem as brilliant as I had hoped.

Modified: trunk/olive/class/WindowsBase/ChangeLog
===================================================================
--- trunk/olive/class/WindowsBase/ChangeLog     2007-01-13 20:40:02 UTC (rev 
70964)
+++ trunk/olive/class/WindowsBase/ChangeLog     2007-01-13 21:37:15 UTC (rev 
70965)
@@ -1,3 +1,9 @@
+2007-01-13  Miguel de Icaza  <[EMAIL PROTECTED]>
+
+       * System.Windows.Threading/Dispatcher.cs: Initially I thought this
+       was a stroke of genius.   Looking at the actual results, it does
+       not seem as brilliant as I had hoped.
+
 2005-07-24  Iain McCoy  <[EMAIL PROTECTED]>
 
        * Test/AttachedProperties.cs: made LocalValueEnumerator test not

Modified: trunk/olive/class/WindowsBase/System.Windows.Threading/Dispatcher.cs
===================================================================
--- trunk/olive/class/WindowsBase/System.Windows.Threading/Dispatcher.cs        
2007-01-13 20:40:02 UTC (rev 70964)
+++ trunk/olive/class/WindowsBase/System.Windows.Threading/Dispatcher.cs        
2007-01-13 21:37:15 UTC (rev 70965)
@@ -67,6 +67,7 @@
                int queue_bits;
                EventWaitHandle wait;
                Queue async_tasks;
+               bool want_async_lookup;
                
                Dispatcher (Thread t)
                {
@@ -138,7 +139,7 @@
 
                void Queue (DispatcherPriority priority, object x)
                {
-                       int p = ((int) priority)-TOP_PRIO;
+                       int p = ((int) priority);
                        Queue q = priority_queues [p];
                        int flag = 1 << p;
                        q.Enqueue (x);
@@ -148,6 +149,7 @@
                void QueueAsync (DispatcherPriority priority, object x)
                {
                        lock (async_tasks){
+                               want_async_lookup = true;
                                async_tasks.Enqueue (priority);
                                async_tasks.Enqueue (x);
                        }
@@ -231,24 +233,39 @@
                        bool done = false;
                        do {
                                while (queue_bits != 0){
-                                       for (int i = 0; i < TOP_PRIO; i++){
-                                               if ((queue_bits & (1 << i)) != 
0){
+                                       for (int i = TOP_PRIO; i > 0 && 
queue_bits != 0; i--){
+                                               int current_bit = queue_bits & 
(1 << i);
+                                               if (current_bit != 0){
                                                        object task;
-                                                       
                                                        Queue q = 
priority_queues [i];
-                                                       task = q.Dequeue ();
-                                                       if (q.Count == 0)
-                                                               queue_bits &= 
~(1 << i);
-                                                       InvokeTask (q);
-                                                       break;
+
+                                                       do {
+                                                               task = 
q.Dequeue ();
+
+                                                               // if we are 
done with this queue, leave.
+                                                               if (q.Count == 
0){
+                                                                       
queue_bits &= ~(1 << i);
+                                                                       break;
+                                                               }
+                                                               InvokeTask (q);
+
+                                                               //
+                                                               // If a 
higher-priority task comes in, go do that
+                                                               //
+                                                               if (current_bit 
< (queue_bits & ~current_bit))
+                                                                       break;
+                                                       } while (true);
                                                }
                                        }
                                }
                                wait.WaitOne ();
-                               lock (async_tasks){
-                                       DispatcherPriority p = 
(DispatcherPriority) async_tasks.Dequeue ();
-                                       object task = async_tasks.Dequeue ();
-                                       Queue (p, task);
+                               if (want_async_lookup){
+                                       lock (async_tasks){
+                                               DispatcherPriority p = 
(DispatcherPriority) async_tasks.Dequeue ();
+                                               object task = 
async_tasks.Dequeue ();
+                                               Queue (p, task);
+                                               want_async_lookup = false;
+                                       }
                                }
                        } while (frame.Continue);
                }

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to