Skip to content
Permalink
Browse files
Adds an infinite await method for convenience. Also adds some API docs.
  • Loading branch information
Timothy A. Bish committed Oct 28, 2010
1 parent 1415879 commit 6aafb58f99de769ddfaad69737ea88808dadb8aa
Showing 1 changed file with 19 additions and 0 deletions.
@@ -29,6 +29,9 @@ public CountDownLatch(int i)
remaining = i;
}

/// <summary>
/// Decrement the count, releasing any waiting Threads when the count reaches Zero.
/// </summary>
public void countDown()
{
lock(mutex)
@@ -44,6 +47,9 @@ public void countDown()
}
}

/// <summary>
/// Gets the current count for this Latch.
/// </summary>
public int Remaining
{
get
@@ -55,6 +61,19 @@ public int Remaining
}
}

/// <summary>
/// Causes the current Thread to wait for the count to reach zero, unless
/// the Thread is interrupted.
/// </summary>
public void await()
{
this.await(TimeSpan.FromMilliseconds(Timeout.Infinite));
}

/// <summary>
/// Causes the current thread to wait until the latch has counted down to zero, unless
/// the thread is interrupted, or the specified waiting time elapses.
/// </summary>
public bool await(TimeSpan timeout)
{
return mutex.WaitOne((int) timeout.TotalMilliseconds, false);

0 comments on commit 6aafb58

Please sign in to comment.