Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ WaitMultiple() [1/2]

static int System.Threading.WaitHandle.WaitMultiple ( ReadOnlySpan< WaitHandle > waitHandles,
bool waitAll,
int millisecondsTimeout )
inlinestaticprivate

Definition at line 228 of file WaitHandle.cs.

229 {
230 if (waitHandles.Length == 0)
231 {
232 throw new ArgumentException(SR.Argument_EmptyWaithandleArray, "waitHandles");
233 }
234 if (waitHandles.Length > 64)
235 {
236 throw new NotSupportedException(SR.NotSupported_MaxWaitHandles);
237 }
238 if (millisecondsTimeout < -1)
239 {
240 throw new ArgumentOutOfRangeException("millisecondsTimeout", SR.ArgumentOutOfRange_NeedNonNegOrNegative1);
241 }
242 SynchronizationContext current = SynchronizationContext.Current;
243 bool flag = current?.IsWaitNotificationRequired() ?? false;
244 SafeWaitHandle[] array = RentSafeWaitHandleArray(waitHandles.Length);
245 try
246 {
247 int num;
248 if (flag)
249 {
250 IntPtr[] array2 = new IntPtr[waitHandles.Length];
251 ObtainSafeWaitHandles(waitHandles, array, array2);
252 num = current.Wait(array2, waitAll, millisecondsTimeout);
253 }
254 else
255 {
256 Span<IntPtr> span = stackalloc IntPtr[waitHandles.Length];
257 ObtainSafeWaitHandles(waitHandles, array, span);
259 }
260 if (num >= 128 && num < 128 + waitHandles.Length)
261 {
262 if (waitAll)
263 {
264 throw new AbandonedMutexException();
265 }
266 num -= 128;
267 throw new AbandonedMutexException(num, waitHandles[num]);
268 }
269 return num;
270 }
271 finally
272 {
273 for (int i = 0; i < waitHandles.Length; i++)
274 {
275 SafeWaitHandle safeWaitHandle = array[i];
276 if (safeWaitHandle != null)
277 {
278 safeWaitHandle.DangerousRelease();
279 array[i] = null;
280 }
281 }
283 }
284 }
static SafeWaitHandle[] RentSafeWaitHandleArray(int capacity)
static unsafe int WaitMultipleIgnoringSyncContext(Span< IntPtr > waitHandles, bool waitAll, int millisecondsTimeout)
Definition WaitHandle.cs:69
static void ReturnSafeWaitHandleArray(SafeWaitHandle[] safeWaitHandles)
static void ObtainSafeWaitHandles(ReadOnlySpan< WaitHandle > waitHandles, Span< SafeWaitHandle > safeWaitHandles, Span< IntPtr > unsafeWaitHandles)

References System.SR.Argument_EmptyWaithandleArray, System.SR.ArgumentOutOfRange_NeedNonNegOrNegative1, System.array, System.Threading.SynchronizationContext.Current, System.Runtime.InteropServices.SafeHandle.DangerousRelease(), System.Threading.SynchronizationContext.IsWaitNotificationRequired(), System.ReadOnlySpan< T >.Length, System.millisecondsTimeout, System.SR.NotSupported_MaxWaitHandles, System.Threading.WaitHandle.ObtainSafeWaitHandles(), System.Threading.WaitHandle.RentSafeWaitHandleArray(), System.Threading.WaitHandle.ReturnSafeWaitHandleArray(), System.Threading.SynchronizationContext.Wait(), and System.Threading.WaitHandle.WaitMultipleIgnoringSyncContext().