Show / Hide Table of Contents

Struct AtomicReference<T>

Provides container with atomic operations for the reference type.

Implements
IEquatable<T>
ISerializable
Inherited Members
Object.Equals(Object, Object)
Object.GetType()
Object.ReferenceEquals(Object, Object)
Namespace: DotNext.Threading
Assembly: DotNext.dll
Syntax
[Serializable]
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 Source

AtomicReference(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 Source

Value

Provides volatile access to the reference value.

Declaration
public T Value { get; set; }
Property Value
Type Description
T

Methods

| Improve this Doc View Source

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.

| Improve this Doc View Source

AccumulateAndGet(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.

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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 other value.

| Improve this Doc View Source

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 other value.

Overrides
ValueType.Equals(Object)
| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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
Func<T, T> updater

A side-effect-free function.

Returns
Type Description
T

The original value.

| Improve this Doc View Source

GetHashCode()

Computes hash code for the stored value.

Declaration
public override int GetHashCode()
Returns
Type Description
Int32

The hash code of the stored value.

Overrides
ValueType.GetHashCode()
| Improve this Doc View Source

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.

| Improve this Doc View Source

SetIfNull(Func<T>)

Modifies stored value if it is null.

Declaration
public T SetIfNull(Func<T> supplier)
Parameters
Type Name Description
Func<T> supplier

Supplier of a new value.

Returns
Type Description
T

Modified value.

| Improve this Doc View Source

SetIfNull<TDerived>()

Modifies stored value if it is null.

Declaration
public T SetIfNull<TDerived>()

    where TDerived : T, new()
Returns
Type Description
T

Modified value.

Type Parameters
Name Description
TDerived

A derived type with default constructor.

| Improve this Doc View Source

ToString()

Returns textual representation of the stored value.

Declaration
public override string ToString()
Returns
Type Description
String

The textual representation of the stored value.

Overrides
ValueType.ToString()
| Improve this Doc View Source

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.

| Improve this Doc View Source

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
Func<T, T> updater

A side-effect-free function.

Returns
Type Description
T

The updated value.

Explicit Interface Implementations

| Improve this Doc View Source

ISerializable.GetObjectData(SerializationInfo, StreamingContext)

Declaration
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
Parameters
Type Name Description
SerializationInfo info
StreamingContext context

Implements

System.IEquatable<T>
System.Runtime.Serialization.ISerializable

Extension Methods

Sequence.Skip<TEnumerator, T>(ref TEnumerator, Int32)
ExpressionBuilder.Const<T>(T)
  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX