Unosquare
    Show / Hide Table of Contents

    Class AtomicTypeBase<T>

    Provides a generic implementation of an Atomic (interlocked) type

    Idea taken from Memory model and .NET operations in article: http://igoro.com/archive/volatile-keyword-in-c-memory-model-explained/.

    Inheritance
    Object
    AtomicTypeBase<T>
    AtomicBoolean
    AtomicDateTime
    AtomicDouble
    AtomicInteger
    AtomicLong
    AtomicTimeSpan
    Implements
    IComparable<T>
    IComparable<AtomicTypeBase<T>>
    IEquatable<T>
    IEquatable<AtomicTypeBase<T>>
    Namespace: Swan.Threading
    Syntax
    public abstract class AtomicTypeBase<T> : IComparable, IComparable<T>, IComparable<AtomicTypeBase<T>>, IEquatable<T>, IEquatable<AtomicTypeBase<T>> where T : struct, IComparable, IComparable<T>, IEquatable<T>
    Type Parameters
    Name Description
    T

    The structure type backed by a 64-bit value.

    Constructors

    AtomicTypeBase(Int64)

    Initializes a new instance of the AtomicTypeBase<T> class.

    Declaration
    protected AtomicTypeBase(long initialValue)
    Parameters
    Type Name Description
    Int64 initialValue

    The initial value.

    Properties

    BackingValue

    Gets or sets the backing value.

    Declaration
    protected long BackingValue { get; set; }
    Property Value
    Type Description
    Int64

    Value

    Gets or sets the value.

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

    Methods

    CompareTo(T)

    Compares the value to the other instance.

    Declaration
    public int CompareTo(T other)
    Parameters
    Type Name Description
    T other

    The other instance.

    Returns
    Type Description
    Int32

    0 if equal, 1 if this instance is greater, -1 if this instance is less than.

    CompareTo(AtomicTypeBase<T>)

    Compares the value to the other instance.

    Declaration
    public int CompareTo(AtomicTypeBase<T> other)
    Parameters
    Type Name Description
    AtomicTypeBase<T> other

    The other instance.

    Returns
    Type Description
    Int32

    0 if equal, 1 if this instance is greater, -1 if this instance is less than.

    CompareTo(Object)

    Compares the value to the other instance.

    Declaration
    public int CompareTo(object other)
    Parameters
    Type Name Description
    Object other

    The other instance.

    Returns
    Type Description
    Int32

    0 if equal, 1 if this instance is greater, -1 if this instance is less than.

    Equals(T)

    Declaration
    public bool Equals(T other)
    Parameters
    Type Name Description
    T other
    Returns
    Type Description
    Boolean

    Equals(AtomicTypeBase<T>)

    Declaration
    public bool Equals(AtomicTypeBase<T> other)
    Parameters
    Type Name Description
    AtomicTypeBase<T> other
    Returns
    Type Description
    Boolean

    Equals(Object)

    Determines whether the specified Object, is equal to this instance.

    Declaration
    public override bool Equals(object other)
    Parameters
    Type Name Description
    Object other

    The Object to compare with this instance.

    Returns
    Type Description
    Boolean

    true if the specified Object is equal to this instance; otherwise, false.

    FromLong(Int64)

    Converts from a long value to the target type.

    Declaration
    protected abstract T FromLong(long backingValue)
    Parameters
    Type Name Description
    Int64 backingValue

    The backing value.

    Returns
    Type Description
    T

    The value converted form a long value.

    GetHashCode()

    Returns a hash code for this instance.

    Declaration
    public override int GetHashCode()
    Returns
    Type Description
    Int32

    A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.

    ToLong(T)

    Converts from the target type to a long value.

    Declaration
    protected abstract long ToLong(T value)
    Parameters
    Type Name Description
    T value

    The value.

    Returns
    Type Description
    Int64

    The value converted to a long value.

    Operators

    Addition(AtomicTypeBase<T>, Int64)

    Implements the operator -<.

    Declaration
    public static AtomicTypeBase<T> operator +(AtomicTypeBase<T> instance, long operand)
    Parameters
    Type Name Description
    AtomicTypeBase<T> instance

    The instance.

    Int64 operand

    The operand.

    Returns
    Type Description
    AtomicTypeBase<T>

    The result of the operator.

    Decrement(AtomicTypeBase<T>)

    Implements the operator --.

    Declaration
    public static AtomicTypeBase<T> operator --(AtomicTypeBase<T> instance)
    Parameters
    Type Name Description
    AtomicTypeBase<T> instance

    The instance.

    Returns
    Type Description
    AtomicTypeBase<T>

    The result of the operator.

    Equality(AtomicTypeBase<T>, T)

    Implements the operator ==.

    Declaration
    public static bool operator ==(AtomicTypeBase<T> a, T b)
    Parameters
    Type Name Description
    AtomicTypeBase<T> a

    a.

    T b

    The b.

    Returns
    Type Description
    Boolean

    The result of the operator.

    GreaterThan(AtomicTypeBase<T>, T)

    Implements the operator >.

    Declaration
    public static bool operator>(AtomicTypeBase<T> a, T b)
    Parameters
    Type Name Description
    AtomicTypeBase<T> a

    a.

    T b

    The b.

    Returns
    Type Description
    Boolean

    The result of the operator.

    GreaterThanOrEqual(AtomicTypeBase<T>, T)

    Implements the operator >=.

    Declaration
    public static bool operator >=(AtomicTypeBase<T> a, T b)
    Parameters
    Type Name Description
    AtomicTypeBase<T> a

    a.

    T b

    The b.

    Returns
    Type Description
    Boolean

    The result of the operator.

    Increment(AtomicTypeBase<T>)

    Implements the operator ++.

    Declaration
    public static AtomicTypeBase<T> operator ++(AtomicTypeBase<T> instance)
    Parameters
    Type Name Description
    AtomicTypeBase<T> instance

    The instance.

    Returns
    Type Description
    AtomicTypeBase<T>

    The result of the operator.

    Inequality(AtomicTypeBase<T>, T)

    Implements the operator !=.

    Declaration
    public static bool operator !=(AtomicTypeBase<T> a, T b)
    Parameters
    Type Name Description
    AtomicTypeBase<T> a

    a.

    T b

    The b.

    Returns
    Type Description
    Boolean

    The result of the operator.

    LessThan(AtomicTypeBase<T>, T)

    Implements the operator <.

    Declaration
    public static bool operator <(AtomicTypeBase<T> a, T b)
    Parameters
    Type Name Description
    AtomicTypeBase<T> a

    a.

    T b

    The b.

    Returns
    Type Description
    Boolean

    The result of the operator.

    LessThanOrEqual(AtomicTypeBase<T>, T)

    Implements the operator <=.

    Declaration
    public static bool operator <=(AtomicTypeBase<T> a, T b)
    Parameters
    Type Name Description
    AtomicTypeBase<T> a

    a.

    T b

    The b.

    Returns
    Type Description
    Boolean

    The result of the operator.

    Subtraction(AtomicTypeBase<T>, Int64)

    Implements the operator -.

    Declaration
    public static AtomicTypeBase<T> operator -(AtomicTypeBase<T> instance, long operand)
    Parameters
    Type Name Description
    AtomicTypeBase<T> instance

    The instance.

    Int64 operand

    The operand.

    Returns
    Type Description
    AtomicTypeBase<T>

    The result of the operator.

    Implements

    IComparable<>
    IComparable<>
    IEquatable<>
    IEquatable<>

    Comments

    Back to top Copyright © 2017-2019 Unosquare