Struct InterlockedRef<T>
A lightweight representation of an Interlocked (atomic) ref type.
public struct InterlockedRef<T> : IEquatable<InterlockedRef<T>> where T : class?
Type Parameters
TRef type.
- Implements
- Inherited Members
- Extension Methods
Constructors
InterlockedRef(T)
Creates a new InterlockedRef<T> instance.
public InterlockedRef(T value)
Parameters
valueTInitial 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
valueTValue to set.
comparandTValue 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
otherInterlockedRef<T>An object to compare with this object.
Returns
Equals(object?)
Indicates whether this instance and a specified object are equal.
[Pure]
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare with the current instance.
Returns
- bool
true if
objand 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
valueTValue 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
valueTValue to set.
Returns
- bool
true when value has changed, otherwise false.
Write(T, T)
public bool Write(T value, T expected)
Parameters
valueTValue to set.
expectedTValue 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
aInterlockedRef<T>First operand.
bInterlockedRef<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
aInterlockedRef<T>First operand.
bInterlockedRef<T>Second operand.
Returns
- bool
true when operands are not equal, otherwise false.