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

◆ ThreadProc()

static void System.Net.TimerThread.ThreadProc ( )
inlinestaticprivate

Definition at line 398 of file TimerThread.cs.

399 {
400 lock (s_queues)
401 {
403 {
404 return;
405 }
406 bool flag = true;
407 while (flag)
408 {
409 try
410 {
411 s_threadReadyEvent.Reset();
412 while (true)
413 {
414 if (s_newQueues.Count > 0)
415 {
417 {
418 for (LinkedListNode<WeakReference> first = s_newQueues.First; first != null; first = s_newQueues.First)
419 {
420 s_newQueues.Remove(first);
421 s_queues.AddLast(first);
422 }
423 }
424 }
425 int tickCount = Environment.TickCount;
426 int num = 0;
427 bool flag2 = false;
429 while (linkedListNode != null)
430 {
432 if (timerQueue == null)
433 {
435 s_queues.Remove(linkedListNode);
436 linkedListNode = next;
437 continue;
438 }
439 if (timerQueue.Fire(out var nextExpiration) && (!flag2 || IsTickBetween(tickCount, num, nextExpiration)))
440 {
441 num = nextExpiration;
442 flag2 = true;
443 }
445 }
446 int tickCount2 = Environment.TickCount;
447 int num2 = (int)((!flag2) ? 30000 : (IsTickBetween(tickCount, num, tickCount2) ? (Math.Min((uint)(num - tickCount2), 2147483632u) + 15) : 0));
448 if (System.Net.NetEventSource.Log.IsEnabled())
449 {
450 System.Net.NetEventSource.Info(null, $"Waiting for {num2}ms", "ThreadProc");
451 }
453 if (num3 == 0)
454 {
455 if (System.Net.NetEventSource.Log.IsEnabled())
456 {
457 System.Net.NetEventSource.Info(null, "Awoke, cause: Shutdown", "ThreadProc");
458 }
459 flag = false;
460 break;
461 }
462 if (System.Net.NetEventSource.Log.IsEnabled())
463 {
464 System.Net.NetEventSource.Info(null, FormattableStringFactory.Create("Awoke, cause {0}", (num3 == 258) ? "Timeout" : "Prod"), "ThreadProc");
465 }
466 if (num3 == 258 && !flag2)
467 {
469 if (!s_threadReadyEvent.WaitOne(0, exitContext: false) || Interlocked.CompareExchange(ref s_threadState, 1, 0) != 0)
470 {
471 flag = false;
472 break;
473 }
474 }
475 }
476 }
477 catch (Exception ex)
478 {
480 {
481 throw;
482 }
483 if (System.Net.NetEventSource.Log.IsEnabled())
484 {
485 System.Net.NetEventSource.Error(null, ex, "ThreadProc");
486 }
487 Thread.Sleep(1000);
488 }
489 }
490 }
491 if (System.Net.NetEventSource.Log.IsEnabled())
492 {
493 System.Net.NetEventSource.Info(null, "Stop", "ThreadProc");
494 }
495 }
static bool IsFatal(Exception exception)
static readonly System.Net.NetEventSource Log
static void Info(object thisOrContextObject, FormattableString formattableString=null, [CallerMemberName] string memberName=null)
static void Error(object thisOrContextObject, FormattableString formattableString, [CallerMemberName] string memberName=null)
static readonly AutoResetEvent s_threadReadyEvent
static readonly LinkedList< WeakReference > s_queues
static bool IsTickBetween(int start, int end, int comparand)
static readonly LinkedList< WeakReference > s_newQueues
static readonly WaitHandle[] s_threadEvents
static FormattableString Create(string format, params object?[] arguments)
static int CompareExchange(ref int location1, int value, int comparand)
static void Sleep(int millisecondsTimeout)
Definition Thread.cs:658
static int WaitAny(WaitHandle[] waitHandles, int millisecondsTimeout)

References System.Threading.Interlocked.CompareExchange(), System.Runtime.CompilerServices.FormattableStringFactory.Create(), System.Net.NetEventSource.Error(), System.Net.NetEventSource.Info(), System.Net.ExceptionCheck.IsFatal(), System.Net.TimerThread.IsTickBetween(), System.Net.NetEventSource.Log, System.Math.Min(), System.Net.TimerThread.s_newQueues, System.Net.TimerThread.s_queues, System.Net.TimerThread.s_threadEvents, System.Net.TimerThread.s_threadReadyEvent, System.Net.TimerThread.s_threadState, System.Threading.Thread.Sleep(), System.Environment.TickCount, and System.Threading.WaitHandle.WaitAny().

Referenced by System.Net.TimerThread.Prod().