Struct AtomicReference<T>
Provides container with atomic operations for the reference type.
Implements
Namespace: DotNext.Threading
Assembly: DotNext.dll
Syntax
public struct AtomicReference<T> : IEquatable<T>, ISerializable where T : class
Type Parameters
| Name | Description |
|---|---|
| T | Type of object to be stored inside of container. |
Remarks
Use this structure in the declaration of integer value. volatile specifier is not needed for such field. Do not pass this structure by value into another methods, otherwise you will get a local copy of the reference not referred to the field.
Constructors
| Improve this Doc View SourceAtomicReference(T)
Initializes a new container with atomic operations for the reference type.
Declaration
public AtomicReference(T value)
Parameters
| Type | Name | Description |
|---|---|---|
| T | value | Initial value to be placed into container. |
Properties
| Improve this Doc View SourceValue
Provides volatile access to the reference value.
Declaration
public T Value { get; set; }
Property Value
| Type | Description |
|---|---|
| T |
Methods
| Improve this Doc View SourceAccumulateAndGet(T, Func<T, T, T>)
Atomically updates the current value with the results of applying the given function to the current and given values, returning the updated value.
Declaration
public T AccumulateAndGet(T x, Func<T, T, T> accumulator)
Parameters
| Type | Name | Description |
|---|---|---|
| T | x | Accumulator operand. |
| DotNext.Func<T, T, T> | accumulator | A side-effect-free function of two arguments |
Returns
| Type | Description |
|---|---|
| T | The updated value. |
Remarks
The function is applied with the current value as its first argument, and the given update as the second argument.
AccumulateAndGet(T, ValueFunc<T, T, T>)
Atomically updates the current value with the results of applying the given function to the current and given values, returning the updated value.
Declaration
public T AccumulateAndGet(T x, in ValueFunc<T, T, T> accumulator)
Parameters
| Type | Name | Description |
|---|---|---|
| T | x | Accumulator operand. |
| ValueFunc<T, T, T> | accumulator | A side-effect-free function of two arguments |
Returns
| Type | Description |
|---|---|
| T | The updated value. |
Remarks
The function is applied with the current value as its first argument, and the given update as the second argument.
CompareAndSet(T, T)
Compares two values for equality and, if they are equal, replaces the stored value.
Declaration
public bool CompareAndSet(T expected, T update)
Parameters
| Type | Name | Description |
|---|---|---|
| T | expected | The expected value. |
| T | update | The new value. |
Returns
| Type | Description |
|---|---|
| Boolean | true if successful. False return indicates that the actual value was not equal to the expected value. |
CompareExchange(T, T)
Compares two values for equality and, if they are equal, replaces the stored value.
Declaration
public T CompareExchange(T expected, T update)
Parameters
| Type | Name | Description |
|---|---|---|
| T | expected | The expected value. |
| T | update | The new value. |
Returns
| Type | Description |
|---|---|
| T | Original (previous) value. |
Equals(T)
Checks whether the stored value is equal to the given value.
Declaration
public bool Equals(T other)
Parameters
| Type | Name | Description |
|---|---|---|
| T | other | Other value to compare. |
Returns
| Type | Description |
|---|---|
| Boolean | true, if the stored value is equal to |
Equals(Object)
Checks whether the stored value is equal to the given value.
Declaration
public override bool Equals(object other)
Parameters
| Type | Name | Description |
|---|---|---|
| Object | other | Other value to compare. |
Returns
| Type | Description |
|---|---|
| Boolean | true, if the stored value is equal to |
GetAndAccumulate(T, Func<T, T, T>)
Atomically updates the current value with the results of applying the given function to the current and given values, returning the original value.
Declaration
public T GetAndAccumulate(T x, Func<T, T, T> accumulator)
Parameters
| Type | Name | Description |
|---|---|---|
| T | x | Accumulator operand. |
| DotNext.Func<T, T, T> | accumulator | A side-effect-free function of two arguments |
Returns
| Type | Description |
|---|---|
| T | The original value. |
Remarks
The function is applied with the current value as its first argument, and the given update as the second argument.
GetAndAccumulate(T, ValueFunc<T, T, T>)
Atomically updates the current value with the results of applying the given function to the current and given values, returning the original value.
Declaration
public T GetAndAccumulate(T x, in ValueFunc<T, T, T> accumulator)
Parameters
| Type | Name | Description |
|---|---|---|
| T | x | Accumulator operand. |
| ValueFunc<T, T, T> | accumulator | A side-effect-free function of two arguments |
Returns
| Type | Description |
|---|---|
| T | The original value. |
Remarks
The function is applied with the current value as its first argument, and the given update as the second argument.
GetAndSet(T)
Modifies value of the container atomically.
Declaration
public T GetAndSet(T update)
Parameters
| Type | Name | Description |
|---|---|---|
| T | update | A new value to be stored inside of container. |
Returns
| Type | Description |
|---|---|
| T | Original value before modification. |
GetAndUpdate(Func<T, T>)
Atomically updates the stored value with the results of applying the given function, returning the original value.
Declaration
public T GetAndUpdate(Func<T, T> updater)
Parameters
| Type | Name | Description |
|---|---|---|
| DotNext.Func<T, T> | updater | A side-effect-free function |
Returns
| Type | Description |
|---|---|
| T | The original value. |
GetAndUpdate(ValueFunc<T, T>)
Atomically updates the stored value with the results of applying the given function, returning the original value.
Declaration
public T GetAndUpdate(in ValueFunc<T, T> updater)
Parameters
| Type | Name | Description |
|---|---|---|
| ValueFunc<T, T> | updater | A side-effect-free function |
Returns
| Type | Description |
|---|---|
| T | The original value. |
GetHashCode()
Computes hash code for the stored value.
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| Int32 | The hash code of the stored value. |
SetAndGet(T)
Modifies value of the container atomically.
Declaration
public T SetAndGet(T update)
Parameters
| Type | Name | Description |
|---|---|---|
| T | update | A new value to be stored inside of container. |
Returns
| Type | Description |
|---|---|
| T | A new value passed as argument. |
SetIfNull(Func<T>)
Modifies stored value if it is null.
Declaration
public T SetIfNull(Func<T> supplier)
Parameters
| Type | Name | Description |
|---|---|---|
| DotNext.Func<T> | supplier | Supplier of a new value. |
Returns
| Type | Description |
|---|---|
| T | Modified value. |
SetIfNull<G>()
Modifies stored value if it is null.
Declaration
public T SetIfNull<G>()
where G : T, new()
Returns
| Type | Description |
|---|---|
| T | Modified value. |
Type Parameters
| Name | Description |
|---|---|
| G | A derived type with default constructor. |
ToString()
Returns textual representation of the stored value.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| String | The textual representation of the stored value. |
UpdateAndGet(Func<T, T>)
Atomically updates the stored value with the results of applying the given function, returning the updated value.
Declaration
public T UpdateAndGet(Func<T, T> updater)
Parameters
| Type | Name | Description |
|---|---|---|
| DotNext.Func<T, T> | updater | A side-effect-free function |
Returns
| Type | Description |
|---|---|
| T | The updated value. |
UpdateAndGet(ValueFunc<T, T>)
Atomically updates the stored value with the results of applying the given function, returning the updated value.
Declaration
public T UpdateAndGet(in ValueFunc<T, T> updater)
Parameters
| Type | Name | Description |
|---|---|---|
| ValueFunc<T, T> | updater | A side-effect-free function |
Returns
| Type | Description |
|---|---|
| T | The updated value. |