final class · System.Threading

ConcurrentQueue<T>

public final class ConcurrentQueue<T>

A queue several threads use at once (a lock around a Queue).

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

Type parameters

NameConstraints
Tany type

Inheritance

Base classes
Any ConcurrentQueue<T>

Constructors

new()
#

Properties

i32 Count { get; }
#

read-only

bool IsEmpty { get; }
#

read-only

Methods

Enqueue(T item)
#
TryDequeue(T fallback) : T
#

The first item, taken out; fallback when the queue is empty.

Dispose()
#

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

Private and internal members (2)

Mutex mutex
#

private

Queue<T> items
#

private

Inherited members (5)

Source

ConcurrentQueue<T> as Antril, decompiled from its Larva HIR.

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

import System;

into namespace System.Threading
{
	/// A queue several threads use at once (a lock around a Queue).
	public final class ConcurrentQueue<T>
	{
		Mutex mutex;
		Queue<T> items;

		public:
			new()
			{
				mutex = new Mutex();
				items = new Queue<T>();
			}

			Enqueue(T item)
			{
				mutex.Lock();
				items.Enqueue(item);
				mutex.Unlock();
			}

			/// The first item, taken out; `fallback` when the queue is empty.
			TryDequeue(T fallback) : T
			{
				mutex.Lock();
				T item = items.Count > 0 ? items.Dequeue() : fallback;
				mutex.Unlock();
				return item;
			}

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

			i32 Count
			{
				get
				{
					mutex.Lock();
					i32 n = items.Count;
					mutex.Unlock();
					return n;
				}
			}

			bool IsEmpty
			{
				get => Count == 0;
			}
	}
}
Esc