//
//
-#if NET_4_0 || MOBILE
+#if NET_4_0
namespace System.Threading
{
ManualResetEvent handle;
internal AtomicBooleanValue disposed;
int used;
- long state;
+ int state;
public ManualResetEventSlim ()
: this (false, 10)
long UpdateStateWithOp (bool set)
{
- long oldValue, newValue;
+ int oldValue, newValue;
do {
oldValue = state;
- newValue = (long)(((oldValue >> 1) + 1) << 1) | (set ? 1u : 0u);
+ newValue = (int)(((oldValue >> 1) + 1) << 1) | (set ? 1 : 0);
} while (Interlocked.CompareExchange (ref state, newValue, oldValue) != oldValue);
return newValue;
}
* we have a mismatch between S and H at the end because the last operations done were
* S3/H1. We thus need to repeat H3 to get to the desired final state.
*/
- long currentState;
+ int currentState;
do {
currentState = state;
if (currentState != stamp && (stamp & 1) != (currentState & 1)) {
SpinWait wait = new SpinWait ();
while (!IsSet) {
- cancellationToken.ThrowIfCancellationRequested ();
-
if (wait.Count < spinCount) {
wait.SpinOnce ();
continue;
break;
}
+ cancellationToken.ThrowIfCancellationRequested ();
+
if (IsSet)
return true;
WaitHandle handle = WaitHandle;
if (cancellationToken.CanBeCanceled) {
- if (WaitHandle.WaitAny (new[] { handle, cancellationToken.WaitHandle }, millisecondsTimeout, false) == 0)
+ var result = WaitHandle.WaitAny (new[] { handle, cancellationToken.WaitHandle }, millisecondsTimeout, false);
+ if (result == 1)
+ throw new OperationCanceledException (cancellationToken);
+ if (result == WaitHandle.WaitTimeout)
return false;
-
- cancellationToken.ThrowIfCancellationRequested ();
} else {
if (!handle.WaitOne (millisecondsTimeout, false))
return false;