final class · System.Threading

CountdownEvent

public final class CountdownEvent

Set once it has been signaled initialCount times: Wait waits for that.

Kind
final class
Namespace
System.Threading
Assembly
System.Core
Access
public, final
Source file
Threading.ant

Inheritance

Base classes
Any CountdownEvent

Constructors

new(i32 initialCount)
#

Properties

i32 CurrentCount { get; }
#

read-only

bool IsSet { get; }
#

read-only

Methods

Signal() : bool
#

One signal: whether that made it zero.

AddCount()
#

One more signal to wait for.

Wait()
#
Wait(i32 milliseconds) : bool
#
Dispose()
#

Frees what it holds (it must not be used after).

Private and internal members (2)

AtomicI32 left
#

private

private

Inherited members (5)

Source

CountdownEvent as Antril, decompiled from its Larva HIR.

System.Threading.CountdownEvent.ant
// System.Threading.CountdownEvent — System.Core (decompiled from Larva HIR)

import System;

into namespace System.Threading
{
	/// Set once it has been signaled `initialCount` times: Wait waits for that.
	public final class CountdownEvent
	{
		AtomicI32 left;
		ManualResetEvent zero;

		public:
			new(i32 initialCount)
			{
				left = new AtomicI32(initialCount);
				zero = new ManualResetEvent(initialCount == 0);
			}

			/// One signal: whether that made it zero.
			Signal() : bool
			{
				i32 now = left.Decrement();
				if (now < 0)
					throw new InvalidOperationError("CountdownEvent: signaled more times than its count");
				if (now == 0)
				{
					zero.Set();
					return true;
				}
				return false;
			}

			/// One more signal to wait for.
			AddCount()
			{
				left.Increment();
			}

			Wait()
			{
				zero.WaitOne();
			}

			Wait(i32 milliseconds) : bool => zero.WaitOne(milliseconds);

			/// Frees what it holds (it must not be used after).
			Dispose()
			{
				zero.Dispose();
			}

			i32 CurrentCount
			{
				get => left.Load();
			}

			bool IsSet
			{
				get => left.Load() == 0;
			}
	}
}
Esc