//
//
-#if NET_4_0 || BOOTSTRAP_NET_4_0
+#if NET_4_0 || MOBILE
using System;
namespace System.Threading
-{
+{
+ [System.Diagnostics.DebuggerDisplayAttribute ("Initial Count={InitialCount}, Current Count={CurrentCount}")]
public class CountdownEvent : IDisposable
{
- int count;
- readonly int initial;
+ int initialCount;
+ int initial;
ManualResetEventSlim evt = new ManualResetEventSlim (false);
- public CountdownEvent (int count)
+ public CountdownEvent (int initialCount)
{
- if (count < 0)
- throw new ArgumentOutOfRangeException ("count is negative");
- this.initial = this.count = count;
+ if (initialCount < 0)
+ throw new ArgumentOutOfRangeException ("initialCount is negative");
+ this.initial = this.initialCount = initialCount;
}
public bool Signal ()
return Signal (1);
}
- public bool Signal (int num)
+ public bool Signal (int signalCount)
{
- if (num <= 0)
- throw new ArgumentOutOfRangeException ("num");
+ if (signalCount <= 0)
+ throw new ArgumentOutOfRangeException ("signalCount");
Action<int> check = delegate (int value) {
if (value < 0)
- throw new InvalidOperationException ("the specified count is larger that CurrentCount");
+ throw new InvalidOperationException ("the specified initialCount is larger that CurrentCount");
};
int newValue;
- if (!ApplyOperation (-num, check, out newValue))
+ if (!ApplyOperation (-signalCount, check, out newValue))
throw new InvalidOperationException ("The event is already set");
if (newValue == 0) {
AddCount (1);
}
- public void AddCount (int num)
+ public void AddCount (int signalCount)
{
- if (num < 0)
- throw new ArgumentOutOfRangeException ("num");
+ if (signalCount < 0)
+ throw new ArgumentOutOfRangeException ("signalCount");
- if (!TryAddCount (num))
+ if (!TryAddCount (signalCount))
throw new InvalidOperationException ("The event is already set");
}
return TryAddCount (1);
}
- public bool TryAddCount (int num)
+ public bool TryAddCount (int signalCount)
{
- if (num < 0)
- throw new ArgumentOutOfRangeException ("num");
+ if (signalCount < 0)
+ throw new ArgumentOutOfRangeException ("signalCount");
- return ApplyOperation (num, null);
+ return ApplyOperation (signalCount, null);
}
bool ApplyOperation (int num, Action<int> doCheck)
newValue = 0;
do {
- oldCount = count;
+ oldCount = initialCount;
if (oldCount == 0)
return false;
if (doCheck != null)
doCheck (newValue);
- } while (Interlocked.CompareExchange (ref count, newValue, oldCount) != oldCount);
+ } while (Interlocked.CompareExchange (ref initialCount, newValue, oldCount) != oldCount);
return true;
}
evt.Wait ();
}
- public void Wait (CancellationToken token)
+ public void Wait (CancellationToken cancellationToken)
{
- evt.Wait (token);
+ evt.Wait (cancellationToken);
}
- public bool Wait (int timeoutMilli)
+ public bool Wait (int millisecondsTimeout)
{
- return evt.Wait (timeoutMilli);
+ return evt.Wait (millisecondsTimeout);
}
- public bool Wait(TimeSpan span)
+ public bool Wait(TimeSpan timeout)
{
- return evt.Wait (span);
+ return evt.Wait (timeout);
}
- public bool Wait (int timeoutMilli, CancellationToken token)
+ public bool Wait (int millisecondsTimeout, CancellationToken cancellationToken)
{
- return evt.Wait (timeoutMilli, token);
+ return evt.Wait (millisecondsTimeout, cancellationToken);
}
- public bool Wait(TimeSpan span, CancellationToken token)
+ public bool Wait(TimeSpan timeout, CancellationToken cancellationToken)
{
- return evt.Wait (span, token);
+ return evt.Wait (timeout, cancellationToken);
}
public void Reset ()
Reset (initial);
}
- public void Reset (int value)
+ public void Reset (int count)
{
evt.Reset ();
- Interlocked.Exchange (ref count, value);
+ initialCount = initial = count;
}
public int CurrentCount {
get {
- return count;
+ return initialCount;
}
}
public bool IsSet {
get {
- return count == 0;
+ return initialCount == 0;
}
}
}
- protected virtual void Dispose (bool managedRes)
+ protected virtual void Dispose (bool disposing)
{
}