Ejemplo n.º 1
0
        protected bool TryExecute(PerlaItem item)
        {
            if (item.ExecutingScheduler != this)
            {
                throw new InvalidOperationException("PerlaScheduler ExecuteMethod WrongScheduler");
            }

            return(item.ExecuteEntry());
        }
Ejemplo n.º 2
0
 protected internal override void QueueTask(PerlaItem item)
 {
     if (item.ExcutionFlag != PerlaExcutionFlag.Single)
     {
         Thread thread = new Thread(s_longRunningThreadWork);
         thread.IsBackground = true;
         thread.Start(item);
     }
 }
Ejemplo n.º 3
0
        internal void UpdateExceptionObservedStatus()
        {
            PerlaItem parent = m_parent;

            if ((parent != null) &&
                PerlaItem.InternalCurrent == parent)
            {
#warning NeedToWorkMore
            }
        }
Ejemplo n.º 4
0
 protected override bool TryExecuteTaskInline(PerlaItem item, bool taskWasPreviouslyQueued)
 {
     if (SynchronizationContext.Current == m_synchronizationContext)
     {
         return(TryExecute(item));
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 5
0
        internal static bool AddToActiveItems(PerlaItem item)
        {
            Debug.Assert(item != null, "Null PerlaItem objects can't be added to the ActiveItems collection");
            LazyInitializer.EnsureInitialized(ref s_currentActiveItems, () => new Dictionary <int, PerlaItem>());
            int itemId = item.Id;

            lock (s_currentActiveItems)
            {
                s_currentActiveItems[itemId] = item;
            }
            return(true);
        }
Ejemplo n.º 6
0
        internal static void RemoveFromActiveItems(PerlaItem item)
        {
            if (s_currentActiveItems == null)
            {
                return;
            }

            int taskId = item.Id;

            lock (s_currentActiveItems)
            {
                s_currentActiveItems.Remove(taskId);
            }
        }
Ejemplo n.º 7
0
 protected override bool TryExecuteTaskInline(PerlaItem item, bool taskWasPreviouslyQueued)
 {
     if (taskWasPreviouslyQueued /*&& !ThreadPool.TryPopCustomWorkItem(item)*/)
     {
         return(false);
     }
     try
     {
         item.ExecuteEntryUnsafe(threadPoolThread: null);
     }
     finally
     {
         if (taskWasPreviouslyQueued)
         {
             NotifyWorkItemProgress();
         }
     }
     return(true);
 }
Ejemplo n.º 8
0
        internal bool TryRunInline(PerlaItem item, bool taskWasPreviouslyQueued)
        {
            PerlaScheduler ets = item.ExecutingScheduler;

            if (ets != this && ets != null)
            {
                return(ets.TryRunInline(item, taskWasPreviouslyQueued));
            }
            if ((ets == null) ||
                (item.m_action == null) ||
                item.IsDelegateInvoked ||
                item.IsCanceled)
            {
                return(false);
            }
            bool inlined = TryExecuteTaskInline(item, taskWasPreviouslyQueued);

            if (inlined && !(item.IsDelegateInvoked || item.IsCanceled))
            {
                throw new InvalidOperationException("PerlaScheduler_InconsistentStateAfterTryExecuteTaskInline");
            }
            return(inlined);
        }
Ejemplo n.º 9
0
        private void ExecuteWithThreadLocal(ref PerlaItem currentItemSlot, Thread threadPoolThread)
        {
            PerlaItem previousItem = currentItemSlot;

            try
            {
                currentItemSlot = this;
                try
                {
                    ExecutionContext ec = CapturedContext;
                    if (ec == null)
                    {
                        InnerInvoke();
                    }
                    else
                    {
                        if (threadPoolThread == null)
                        {
                            ExecutionContext.Run(ec, s_ecCallback, this);
                        }
                        else
                        {
                            ExecutionContext.Run(ec, s_ecCallback, this);
                        }
                    }
                }
                catch (Exception exn)
                {
                    HandleException(exn);
                }
                Finish(true);
            }
            finally
            {
                currentItemSlot = previousItem;
            }
        }
Ejemplo n.º 10
0
 internal void InternalQueueTask(PerlaItem task)
 {
     Debug.Assert(task != null);
     this.QueueTask(task);
 }
Ejemplo n.º 11
0
 protected internal virtual bool TryDequeue(PerlaItem item)
 {
     return(false);
 }
Ejemplo n.º 12
0
 protected abstract bool TryExecuteTaskInline(PerlaItem item, bool taskWasPreviouslyQueued);
Ejemplo n.º 13
0
 protected internal abstract void QueueTask(PerlaItem item);
Ejemplo n.º 14
0
 protected internal override void QueueTask(PerlaItem item)
 {
     m_synchronizationContext.Post(s_postCallback, (object)item);
 }
Ejemplo n.º 15
0
 internal PerlaExceptionHolder(PerlaItem item)
 {
     Debug.Assert(item != null, "Expected a non-null item.");
     m_item = item;
 }
Ejemplo n.º 16
0
 protected internal override bool TryDequeue(PerlaItem item)
 {
     /* return ThreadPool.TryPopCustomWorkItem(item);*/
     return(false);
 }