Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
SwitchToAwaiter.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using System.Runtime.CompilerServices;
5 using System.Threading.Tasks;
6 
7 namespace SiliconStudio.Core.MicroThreading
8 {
9 #if NET45
10  public class SwitchToAwaiter : INotifyCompletion
11 #else
12  public class SwitchToAwaiter
13 #endif
14  {
15  private Scheduler scheduler;
16 
17  private MicroThread microThread;
18 
19  public SwitchToAwaiter(Scheduler scheduler)
20  {
21  this.scheduler = scheduler;
22  this.microThread = null;
23  }
24 
25  public bool IsCompleted
26  {
27  get { return false; }
28  }
29 
30  public void OnCompleted(Action continuation)
31  {
32  microThread = scheduler.Add(() => { continuation(); return Task.FromResult(true); });
33  }
34 
35  public IDisposable GetResult()
36  {
37  return new SwitchMicroThread(microThread);
38  }
39 
41  {
42  return this;
43  }
44 
45  private struct SwitchMicroThread : IDisposable
46  {
47  private MicroThread microThread;
48 
49  public SwitchMicroThread(MicroThread microThread)
50  {
51  this.microThread = microThread;
52  //microThread.SynchronizationContext.IncrementTaskCount();
53  }
54 
55  public void Dispose()
56  {
57  //microThread.SynchronizationContext.DecrementTaskCount();
58  }
59  }
60  }
61 }
Represents an execution context managed by a Scheduler, that can cooperatively yield execution to ano...
Definition: MicroThread.cs:16
Scheduler that manage a group of cooperating MicroThread.
Definition: Scheduler.cs:20