Dispatcher(Thread t)
 {
     base_thread = t;
     for (int i = 1; i <= (int)DispatcherPriority.Send; i++)
     {
         priority_queues [i] = new PokableQueue();
     }
     wait  = new EventWaitHandle(false, EventResetMode.AutoReset);
     hooks = new DispatcherHooks(this);
 }
예제 #2
0
파일: Dispatcher.cs 프로젝트: raj581/Marvin
        internal void Reprioritize(DispatcherOperation op, DispatcherPriority oldpriority)
        {
            int          oldp = (int)oldpriority;
            PokableQueue q    = priority_queues [oldp];

            lock (q){
                q.Remove(op);
            }
            Queue(op.Priority, op);
            hooks.EmitOperationPriorityChanged(op);
        }
예제 #3
0
파일: Dispatcher.cs 프로젝트: raj581/Marvin
        void Queue(DispatcherPriority priority, DispatcherOperation x)
        {
            int          p = ((int)priority);
            PokableQueue q = priority_queues [p];

            lock (q){
                int flag = 1 << p;
                q.Enqueue(x);
                queue_bits |= flag;
            }
            hooks.EmitOperationPosted(x);

            if (Thread.CurrentThread != base_thread)
            {
                wait.Set();
            }
        }
        void RunFrame(DispatcherFrame frame)
        {
            do
            {
                while (queue_bits != 0)
                {
                    for (int i = TOP_PRIO; i > 0 && queue_bits != 0; i--)
                    {
                        int current_bit = queue_bits & (1 << i);
                        if (current_bit != 0)
                        {
                            PokableQueue q = priority_queues [i];

                            do
                            {
                                DispatcherOperation task;

                                lock (q)
                                {
                                    task = (DispatcherOperation)q.Dequeue();
                                }

                                task.Invoke();

                                //
                                // call hooks.
                                //
                                if (task.Status == DispatcherOperationStatus.Aborted)
                                {
                                    hooks.EmitOperationAborted(task);
                                }
                                else
                                {
                                    hooks.EmitOperationCompleted(task);
                                }

                                if (!frame.Continue)
                                {
                                    return;
                                }

                                if (HasShutdownStarted)
                                {
                                    PerformShutdown();
                                    return;
                                }

                                // if we are done with this queue, leave.
                                lock (q)
                                {
                                    if (q.Count == 0)
                                    {
                                        queue_bits &= ~(1 << i);
                                        break;
                                    }
                                }

                                //
                                // If a higher-priority task comes in, go do that
                                //
                                if (current_bit < (queue_bits & ~current_bit))
                                {
                                    break;
                                }
                            }while (true);
                        }
                    }
                }
                hooks.EmitInactive();

                wait.WaitOne();
                wait.Reset();
            }while (frame.Continue);
        }
예제 #5
0
파일: Dispatcher.cs 프로젝트: NuGardt/mono
		Dispatcher (Thread t)
		{
			base_thread = t;
			for (int i = 1; i <= (int) DispatcherPriority.Send; i++)
				priority_queues [i] = new PokableQueue ();
			wait = new EventWaitHandle (false, EventResetMode.AutoReset);
			hooks = new DispatcherHooks (this);
		}