Author: miguel
Date: 2007-01-11 23:44:25 -0500 (Thu, 11 Jan 2007)
New Revision: 70898

Added:
   trunk/olive/class/WindowsBase/System.Windows.Threading/DispatcherFrame.cs
Modified:
   trunk/olive/class/WindowsBase/System.Windows.Threading/Dispatcher.cs
   trunk/olive/class/WindowsBase/WindowsBase.dll.sources
Log:
More spare time hacking, getting a hang on the frames

Modified: trunk/olive/class/WindowsBase/System.Windows.Threading/Dispatcher.cs
===================================================================
--- trunk/olive/class/WindowsBase/System.Windows.Threading/Dispatcher.cs        
2007-01-12 04:24:39 UTC (rev 70897)
+++ trunk/olive/class/WindowsBase/System.Windows.Threading/Dispatcher.cs        
2007-01-12 04:44:25 UTC (rev 70898)
@@ -9,7 +9,12 @@
 // The documentation for the Dispatcher family is poorly written, complete
 // sections are cut-and-pasted that add no value and the important pieces
 // like (what is a frame) is not on the APIs, but scattered everywhere else
+//
+// TODO:
+//    Add support for disabling the dispatcher and resuming it.
+//    Add support for Waiting for new tasks to be pushed, so that we dont busy 
loop.
 // 
+// -----------------------------------------------------------------------
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
 // "Software"), to deal in the Software without restriction, including
@@ -33,6 +38,7 @@
 //
 // Authors:
 //     Miguel de Icaza ([EMAIL PROTECTED])
+//
 using System;
 using System.Collections;
 using System.Collections.Generic;
@@ -44,13 +50,15 @@
        [Flags]
        internal enum Flags {
                ShutdownStarted = 1,
-               Shutdown = 2
+               Shutdown = 2,
+               Disabled = 4
        }
        
        public sealed class Dispatcher {
                static Dictionary<Thread, Dispatcher> dispatchers = new 
Dictionary<Thread, Dispatcher> ();
                static object olock = new object ();
-
+               static DispatcherFrame main_execution_frame = new 
DispatcherFrame ();
+               
                Thread base_thread;
                Queue [] priority_queues = new Queue 
[(int)DispatcherPriority.Send];
 
@@ -177,29 +185,55 @@
                        }
                }
 
-#if false
-               //
-               // Ok, this currently does not work, because its supposed to
-               // "push" the current frame, and that probably is what contains
-               // the actual Dispatchers
-               //
                public static void Run ()
                {
+                       PushFrame (main_execution_frame);
+               }
+               
+               public static void PushFrame (DispatcherFrame frame)
+               {
+                       if (frame == null)
+                               throw new ArgumentNullException ("frame");
+
+                       Dispatcher dis = CurrentDispatcher;
+
+                       if (dis.HasShutdownFinished)
+                               throw new InvalidOperationException ("The 
Dispatcher has shut down");
+                       if (frame.dispatcher != null)
+                               throw new InvalidOperationException ("Frame is 
already running on a different dispatcher");
+                       if ((dis.flags & Flags.Disabled) != 0)
+                               throw new InvalidOperationException 
("Dispatcher processing has been disabled");
+                       
+                       frame.dispatcher = dis;
+
+                       dis.RunFrame (frame);
+               }
+
+               void RunFrame (DispatcherFrame frame)
+               {
                        bool done = false;
-                       
                        do {
-                               for (int i = 1; i < DispatcherPriority.Send; 
i++){
-                                       queue = priority_queues [i];
+                               //
+                               // FIXME: instead of going top to bottom, we 
should
+                               // actually keep a pointer on each iteration 
and maintain
+                               // it, to always pick the highest-priority item.
+                               //
+                               for (int i = (int) DispatcherPriority.Send; i 
>= 1; i++){
+                                       Queue queue = priority_queues [i];
 
                                        while (queue.Count != 0){
                                                object x = queue.Dequeue ();
                                                Interlocked.Decrement (ref 
events);
-                                               Invoke (x);
+                                               InvokeTask (x);
                                        }
                                }
-                       } while (true);
+                               //
+                               // TODO: add event handling, to avoid busy 
looping
+                               //
+                               // TODO: What about Shutdown?
+                               //
+                       } while (frame.Continue);
                }
-#endif
                
                public bool HasShutdownStarted {
                        get {

Added: trunk/olive/class/WindowsBase/System.Windows.Threading/DispatcherFrame.cs
===================================================================
--- trunk/olive/class/WindowsBase/System.Windows.Threading/DispatcherFrame.cs   
2007-01-12 04:24:39 UTC (rev 70897)
+++ trunk/olive/class/WindowsBase/System.Windows.Threading/DispatcherFrame.cs   
2007-01-12 04:44:25 UTC (rev 70898)
@@ -0,0 +1,60 @@
+// 
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// Copyright (c) 2006 Novell, Inc. (http://www.novell.com)
+//
+// Authors:
+//     Miguel de Icaza ([EMAIL PROTECTED])
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Threading;
+
+namespace System.Windows.Threading {
+
+       public class DispatcherFrame : DispatcherObject  {
+               bool exit_on_request;
+               bool cont;
+               internal Dispatcher dispatcher;
+               
+               public DispatcherFrame ()
+               {
+                       exit_on_request = true;
+                       cont = true;
+               }
+
+               public DispatcherFrame (bool exitWhenRequested)
+               {
+                       exit_on_request = exitWhenRequested;
+                       cont = true;
+               }
+
+               public bool Continue {
+                       get {
+                               return cont;
+                       }
+
+                       set {
+                               cont = value;
+                       }
+               }
+       }
+}


Property changes on: 
trunk/olive/class/WindowsBase/System.Windows.Threading/DispatcherFrame.cs
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: trunk/olive/class/WindowsBase/WindowsBase.dll.sources
===================================================================
--- trunk/olive/class/WindowsBase/WindowsBase.dll.sources       2007-01-12 
04:24:39 UTC (rev 70897)
+++ trunk/olive/class/WindowsBase/WindowsBase.dll.sources       2007-01-12 
04:44:25 UTC (rev 70898)
@@ -8,6 +8,7 @@
 System.Windows/PropertyMetadata.cs
 System.Windows/RoutedEvent.cs
 System.Windows.Threading/Dispatcher.cs
+System.Windows.Threading/DispatcherFrame.cs
 System.Windows.Threading/DispatcherObject.cs
 System.Windows.Threading/DispatcherPriority.cs
 ../../build/common/MonoTODOAttribute.cs

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

Reply via email to