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

◆ ContinueTryEnter()

void System.Threading.SpinLock.ContinueTryEnter ( int millisecondsTimeout,
ref bool lockTaken )
inlineprivate

Definition at line 139 of file SpinLock.cs.

140 {
141 if (lockTaken)
142 {
143 lockTaken = false;
144 throw new ArgumentException(SR.SpinLock_TryReliableEnter_ArgumentException);
145 }
146 if (millisecondsTimeout < -1)
147 {
148 throw new ArgumentOutOfRangeException("millisecondsTimeout", millisecondsTimeout, SR.SpinLock_TryEnter_ArgumentOutOfRange);
149 }
150 uint startTime = 0u;
152 {
153 startTime = TimeoutHelper.GetTime();
154 }
156 {
158 return;
159 }
160 int num = int.MaxValue;
161 int owner = _owner;
162 if ((owner & 1) == 0)
163 {
164 if (CompareExchange(ref _owner, owner | 1, owner, ref lockTaken) == owner || millisecondsTimeout == 0)
165 {
166 return;
167 }
168 }
169 else
170 {
171 if (millisecondsTimeout == 0)
172 {
173 return;
174 }
175 if ((owner & 0x7FFFFFFE) != 2147483646)
176 {
177 num = (Interlocked.Add(ref _owner, 2) & 0x7FFFFFFE) >> 1;
178 }
179 }
180 SpinWait spinWait = default(SpinWait);
181 if (num > Environment.ProcessorCount)
182 {
183 spinWait.Count = 10;
184 }
185 do
186 {
187 spinWait.SpinOnce(40);
188 owner = _owner;
189 if ((owner & 1) == 0)
190 {
191 int value = (((owner & 0x7FFFFFFE) == 0) ? (owner | 1) : ((owner - 2) | 1));
192 if (CompareExchange(ref _owner, value, owner, ref lockTaken) == owner)
193 {
194 return;
195 }
196 }
197 }
198 while (spinWait.Count % 10 != 0 || millisecondsTimeout == -1 || TimeoutHelper.UpdateTimeOut(startTime, millisecondsTimeout) > 0);
200 }
void ContinueTryEnterWithThreadTracking(int millisecondsTimeout, uint startTime, ref bool lockTaken)
Definition SpinLock.cs:217
static int CompareExchange(ref int location, int value, int comparand, ref bool success)
Definition SpinLock.cs:78

References System.Threading.SpinLock._owner, System.Threading.Interlocked.Add(), System.Threading.SpinLock.CompareExchange(), System.Threading.SpinLock.ContinueTryEnterWithThreadTracking(), System.Threading.SpinWait.Count, System.Threading.SpinLock.DecrementWaiters(), System.Threading.TimeoutHelper.GetTime(), System.Threading.SpinLock.IsThreadOwnerTrackingEnabled, System.millisecondsTimeout, System.Environment.ProcessorCount, System.SR.SpinLock_TryEnter_ArgumentOutOfRange, System.SR.SpinLock_TryReliableEnter_ArgumentException, System.Threading.SpinWait.SpinOnce(), System.Threading.TimeoutHelper.UpdateTimeOut(), and System.value.

Referenced by System.Threading.SpinLock.Enter(), System.Threading.SpinLock.TryEnter(), and System.Threading.SpinLock.TryEnter().