コード例 #1
0
        /// <summary>
        /// Creates a micro thread out of the specified function and schedules it as last micro thread to run in this scheduler.
        /// Note that in case of multithreaded scheduling, it might start before this function returns.
        /// </summary>
        /// <param name="microThreadFunction">The function to create a micro thread from.</param>
        /// <param name="flags">The flags.</param>
        /// <returns>A micro thread.</returns>
        public MicroThread Add(Func <Task> microThreadFunction, MicroThreadFlags flags = MicroThreadFlags.None)
        {
            var microThread = new MicroThread(this, flags);

            microThread.Start(microThreadFunction);
            return(microThread);
        }
コード例 #2
0
 public CallbackFromActionBuilder(MicroThread microThread)
 {
     MicroThreadCallback = () =>
     {
         microThread.ThrowIfExceptionRequest();
         MicroThreadAction();
         microThread.ThrowIfExceptionRequest();
     };
 }
コード例 #3
0
 public CallbackSendPostCallbackBuilder(MicroThread microThread)
 {
     MicroThreadCallback = () =>
     {
         microThread.ThrowIfExceptionRequest();
         SendOrPostCallback(CallbackState);
         microThread.ThrowIfExceptionRequest();
     };
 }
コード例 #4
0
        public static ChannelMicroThreadAwaiter <T> New(MicroThread microThread)
        {
            lock (pool)
            {
                if (pool.Count > 0)
                {
                    var index    = pool.Count - 1;
                    var lastItem = pool[index];
                    pool.RemoveAt(index);

                    lastItem.MicroThread = microThread;

                    return(lastItem);
                }

                return(new ChannelMicroThreadAwaiter <T>(microThread));
            }
        }
コード例 #5
0
        public T GetResult()
        {
            // Check Task Result (exception, etc...)
            var result = Result;

            // After result has been taken, we can reuse this item, so put it in the pool
            // We mitigate pool size, but another approach than hard limit might be interesting
            lock (pool)
            {
                if (pool.Count < 4096)
                {
                    isCompleted  = false;
                    MicroThread  = null;
                    Continuation = null;
                    Result       = default(T);
                }

                pool.Add(this);
            }

            return(result);
        }
コード例 #6
0
 public MicroThreadYieldAwaiter(MicroThread microThread)
 {
     this.microThread = microThread;
 }
コード例 #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SchedulerThreadEventArgs"/> class.
 /// </summary>
 /// <param name="microThread">The micro thread.</param>
 /// <param name="threadId">The managed thread identifier.</param>
 public SchedulerThreadEventArgs(MicroThread microThread, int threadId)
 {
     MicroThread = microThread;
     ThreadId    = threadId;
 }
コード例 #8
0
 public ChannelMicroThreadAwaiter(MicroThread microThread)
 {
     MicroThread = microThread;
 }
コード例 #9
0
ファイル: SchedulerEventArgs.cs プロジェクト: cg123/xenko
 /// <summary>
 /// Initializes a new instance of the <see cref="SchedulerThreadEventArgs"/> class.
 /// </summary>
 /// <param name="microThread">The micro thread.</param>
 /// <param name="threadId">The managed thread identifier.</param>
 public SchedulerThreadEventArgs(MicroThread microThread, int threadId)
 {
     MicroThread = microThread;
     ThreadId = threadId;
 }
コード例 #10
0
 public MicrothreadProxySynchronizationContext(MicroThread microThread)
 {
     this.microThread = microThread;
 }
コード例 #11
0
 public void OnCompleted(Action continuation)
 {
     microThread = scheduler.Add(() => { continuation(); return Task.FromResult(true); });
 }
コード例 #12
0
 public SwitchToAwaiter(Scheduler scheduler)
 {
     this.scheduler = scheduler;
     this.microThread = null;
 }
コード例 #13
0
 public MicroThreadYieldAwaiter(MicroThread microThread)
 {
     this.microThread = microThread;
 }
コード例 #14
0
 public SwitchMicroThread(MicroThread microThread)
 {
     this.microThread = microThread;
     //microThread.SynchronizationContext.IncrementTaskCount();
 }
コード例 #15
0
 public void OnCompleted(Action continuation)
 {
     microThread = scheduler.Add(() => { continuation(); return(Task.FromResult(true)); });
 }
コード例 #16
0
 public SwitchToAwaiter(Scheduler scheduler)
 {
     this.scheduler   = scheduler;
     this.microThread = null;
 }
コード例 #17
0
 public SwitchMicroThread(MicroThread microThread)
 {
     this.microThread = microThread;
     //microThread.SynchronizationContext.IncrementTaskCount();
 }
コード例 #18
0
ファイル: Scheduler.cs プロジェクト: Powerino73/paradox
 /// <summary>
 /// Creates a micro thread out of the specified function and schedules it as last micro thread to run in this scheduler.
 /// Note that in case of multithreaded scheduling, it might start before this function returns.
 /// </summary>
 /// <param name="microThreadFunction">The function to create a micro thread from.</param>
 /// <param name="flags">The flags.</param>
 /// <returns>A micro thread.</returns>
 public MicroThread Add(Func<Task> microThreadFunction, MicroThreadFlags flags = MicroThreadFlags.None)
 {
     var microThread = new MicroThread(this, flags);
     microThread.Start(microThreadFunction);
     return microThread;
 }
コード例 #19
0
 public MicroThreadSynchronizationContext(MicroThread microThread)
 {
     this.MicroThread = microThread;
 }
コード例 #20
0
 public MicroThreadSynchronizationContext(MicroThread microThread)
 {
     this.MicroThread = microThread;
 }
コード例 #21
0
 public SchedulerEntry(MicroThread microThread) : this()
 {
     MicroThread = microThread;
 }
 public MicrothreadProxySynchronizationContext(MicroThread microThread)
 {
     this.microThread = microThread;
 }