Table of Contents

Struct InterlockedRef<T>

Namespace
LfrlAnvil.Async
Assembly
LfrlAnvil.Core.dll

A lightweight representation of an Interlocked (atomic) ref type.

public struct InterlockedRef<T> : IEquatable<InterlockedRef<T>> where T : class?

Type Parameters

T

Ref type.

Implements
Inherited Members
Extension Methods

Constructors

InterlockedRef(T)

Creates a new InterlockedRef<T> instance.

public InterlockedRef(T value)

Parameters

value T

Initial value.

Properties

Value

Current value.

public T Value { get; }

Property Value

T

Methods

CompareExchange(T, T)

Sets Value to the provided value only if the current Value is equal to the provided comparand and returns the old value.

public T CompareExchange(T value, T comparand)

Parameters

value T

Value to set.

comparand T

Value used for Value comparison.

Returns

T

Value before the change.

Equals(InterlockedRef<T>)

Indicates whether the current object is equal to another object of the same type.

[Pure]
public bool Equals(InterlockedRef<T> other)

Parameters

other InterlockedRef<T>

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

Equals(object?)

Indicates whether this instance and a specified object are equal.

[Pure]
public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if obj and this instance are the same type and represent the same value; otherwise, false.

Exchange(T)

Sets Value to the provided value and returns the old value.

public T Exchange(T value)

Parameters

value T

Value to set.

Returns

T

Value before the change.

GetHashCode()

Returns the hash code for this instance.

[Pure]
public override int GetHashCode()

Returns

int

A 32-bit signed integer that is the hash code for this instance.

ToString()

Returns a string representation of this InterlockedRef<T> instance.

[Pure]
public override string ToString()

Returns

string

String representation.

Write(T)

Sets Value to the provided value.

public bool Write(T value)

Parameters

value T

Value to set.

Returns

bool

true when value has changed, otherwise false.

Write(T, T)

Sets Value to the provided value only if the current Value is equal to the provided expected.

public bool Write(T value, T expected)

Parameters

value T

Value to set.

expected T

Value used for Value comparison.

Returns

bool

true when value has changed, otherwise false.

Operators

operator ==(InterlockedRef<T>, InterlockedRef<T>)

Checks if a is equal to b.

public static bool operator ==(InterlockedRef<T> a, InterlockedRef<T> b)

Parameters

a InterlockedRef<T>

First operand.

b InterlockedRef<T>

Second operand.

Returns

bool

true when operands are equal, otherwise false.

operator !=(InterlockedRef<T>, InterlockedRef<T>)

Checks if a is not equal to b.

public static bool operator !=(InterlockedRef<T> a, InterlockedRef<T> b)

Parameters

a InterlockedRef<T>

First operand.

b InterlockedRef<T>

Second operand.

Returns

bool

true when operands are not equal, otherwise false.