Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ParallelLoopStateFlags.cs
Go to the documentation of this file.
2
4{
5 private volatile int _loopStateFlags;
6
8
9 internal bool AtomicLoopStateUpdate(int newState, int illegalStates)
10 {
11 int oldState = 0;
12 return AtomicLoopStateUpdate(newState, illegalStates, ref oldState);
13 }
14
15 internal bool AtomicLoopStateUpdate(int newState, int illegalStates, ref int oldState)
16 {
17 SpinWait spinWait = default(SpinWait);
18 while (true)
19 {
20 oldState = _loopStateFlags;
21 if ((oldState & illegalStates) != 0)
22 {
23 return false;
24 }
25 if (Interlocked.CompareExchange(ref _loopStateFlags, oldState | newState, oldState) == oldState)
26 {
27 break;
28 }
29 spinWait.SpinOnce();
30 }
31 return true;
32 }
33
34 internal void SetExceptional()
35 {
37 }
38
46
47 internal bool Cancel()
48 {
49 return AtomicLoopStateUpdate(8, 0);
50 }
51}
static string ParallelState_Stop_InvalidOperationException_StopAfterBreak
Definition SR.cs:26
Definition SR.cs:7
static int CompareExchange(ref int location1, int value, int comparand)
bool AtomicLoopStateUpdate(int newState, int illegalStates)
bool AtomicLoopStateUpdate(int newState, int illegalStates, ref int oldState)