Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
TaskScheduler.cs
Go to the documentation of this file.
4
6
7[DebuggerDisplay("Id={Id}")]
8[DebuggerTypeProxy(typeof(SystemThreadingTasks_TaskSchedulerDebugView))]
9public abstract class TaskScheduler
10{
24
26 {
27 private readonly TaskScheduler _scheduler;
28
29 public bool IsCompleted => false;
30
35
36 public void GetResult()
37 {
38 }
39
40 public void OnCompleted(Action continuation)
41 {
43 }
44
45 public void UnsafeOnCompleted(Action continuation)
46 {
47 if (_scheduler == Default)
48 {
50 {
51 s();
52 }, continuation, preferLocal: true);
53 }
54 else
55 {
57 }
58 }
59 }
60
62
64
65 internal static int s_taskSchedulerIdCounter;
66
67 private volatile int m_taskSchedulerId;
68
69 public virtual int MaximumConcurrencyLevel => int.MaxValue;
70
72
74
76 {
77 get
78 {
80 if (internalCurrent == null || (internalCurrent.CreationOptions & TaskCreationOptions.HideScheduler) != 0)
81 {
82 return null;
83 }
84 return internalCurrent.ExecutingTaskScheduler;
85 }
86 }
87
88 public int Id
89 {
90 get
91 {
92 if (m_taskSchedulerId == 0)
93 {
94 int num;
95 do
96 {
98 }
99 while (num == 0);
101 }
102 return m_taskSchedulerId;
103 }
104 }
105
107
108 protected internal abstract void QueueTask(Task task);
109
111
113
115 {
116 TaskScheduler executingTaskScheduler = task.ExecutingTaskScheduler;
117 if (executingTaskScheduler != this && executingTaskScheduler != null)
118 {
120 }
121 if (executingTaskScheduler == null || (object)task.m_action == null || task.IsDelegateInvoked || task.IsCanceled || !RuntimeHelpers.TryEnsureSufficientExecutionStack())
122 {
123 return false;
124 }
125 if (TplEventSource.Log.IsEnabled())
126 {
127 task.FireTaskScheduledIfNeeded(this);
128 }
130 if (flag && !task.IsDelegateInvoked && !task.IsCanceled)
131 {
133 }
134 return flag;
135 }
136
137 protected internal virtual bool TryDequeue(Task task)
138 {
139 return false;
140 }
141
142 internal virtual void NotifyWorkItemProgress()
143 {
144 }
145
147 {
148 if (TplEventSource.Log.IsEnabled())
149 {
150 task.FireTaskScheduledIfNeeded(this);
151 }
153 }
154
155 protected TaskScheduler()
156 {
158 {
160 }
161 }
162
173
178
179 protected bool TryExecuteTask(Task task)
180 {
181 if (task.ExecutingTaskScheduler != this)
182 {
184 }
185 return task.ExecuteEntry();
186 }
187
189 {
191 }
192
194 {
196 if (scheduledTasks == null)
197 {
198 return null;
199 }
201 if (array == null)
202 {
203 array = new List<Task>(scheduledTasks).ToArray();
204 }
205 Task[] array2 = array;
206 foreach (Task task in array2)
207 {
208 _ = task.Id;
209 }
210 return array;
211 }
212
214 {
215 if (s_activeTaskSchedulers == null)
216 {
217 return new TaskScheduler[1] { s_defaultTaskScheduler };
218 }
221 {
222 list.Add(item.Key);
223 }
224 if (!list.Contains(s_defaultTaskScheduler))
225 {
227 }
228 TaskScheduler[] array = list.ToArray();
231 {
232 _ = taskScheduler.Id;
233 }
234 return array;
235 }
236
238 {
239 return new TaskSchedulerAwaiter(this);
240 }
241}
void Add(TKey key, TValue value)
static string TaskScheduler_ExecuteTask_WrongTaskScheduler
Definition SR.cs:1974
static string TaskScheduler_InconsistentStateAfterTryExecuteTaskInline
Definition SR.cs:1978
Definition SR.cs:7
static int CompareExchange(ref int location1, int value, int comparand)
static int Increment(ref int location)
virtual bool TryDequeue(Task task)
static TaskScheduler FromCurrentSynchronizationContext()
static TaskScheduler[] GetTaskSchedulersForDebugger()
static void PublishUnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs ueea)
static ConditionalWeakTable< TaskScheduler, object > s_activeTaskSchedulers
static ? EventHandler< UnobservedTaskExceptionEventArgs > UnobservedTaskException
bool TryExecuteTaskInline(Task task, bool taskWasPreviouslyQueued)
static readonly TaskScheduler s_defaultTaskScheduler
static ? TaskScheduler InternalCurrent
IEnumerable< Task >? GetScheduledTasks()
bool TryRunInline(Task task, bool taskWasPreviouslyQueued)
static new TaskFactory< TResult > Factory
Definition Task.cs:56
static ? Task InternalCurrent
Definition Task.cs:1011
static readonly TplEventSource Log
static bool UnsafeQueueUserWorkItem(WaitCallback callBack, object? state)