final class · System.Reflection

Reentrant

final class Reentrant

A lock that the thread holding it may take again (the slow path of typeof may describe other types meanwhile).

Kind
final class
Namespace
System.Reflection
Assembly
System.Core
Access
internal, final
Source file
Reflection.ant

Inheritance

Base classes
Any Reentrant

Constructors

new()
#

Methods

Enter()
#
Exit()
#

Private and internal members (3)

readonly Mutex mutex
#

private

i32 owner
#

private

i32 depth
#

private

Inherited members (5)

Source

Reentrant as Antril, decompiled from its Larva HIR.

System.Reflection.Reentrant.ant
// System.Reflection.Reentrant — System.Core (decompiled from Larva HIR)

import System.Threading;

into namespace System.Reflection
{
	/// A lock that the thread holding it may take again (the slow path of `typeof` may describe other types meanwhile).
	final class Reentrant
	{
		readonly Mutex mutex;
		i32 owner;
		i32 depth;

		public:
			new()
			{
				mutex = new Mutex();
			}

			Enter()
			{
				i32 me = Thread.CurrentId;
				if (owner == me && depth > 0)
				{
					depth++;
					return;
				}
				mutex.Lock();
				owner = me;
				depth = 1;
			}

			Exit()
			{
				depth--;
				if (depth == 0)
				{
					owner = 0;
					mutex.Unlock();
				}
			}
	}
}
Esc