Table of Contents

Struct InterlockedInt64

Namespace
LfrlAnvil.Async
Assembly
LfrlAnvil.Core.dll

A lightweight representation of an Interlocked (atomic) long.

public struct InterlockedInt64 : IEquatable<InterlockedInt64>, IComparable<InterlockedInt64>, IComparable
Implements
Inherited Members
Extension Methods

Constructors

InterlockedInt64(long)

Creates a new InterlockedInt64 instance.

public InterlockedInt64(long value)

Parameters

value long

Initial value.

Properties

Value

Current value.

public long Value { get; }

Property Value

long

Methods

Add(long)

Adds provided value to the current Value.

public long Add(long value)

Parameters

value long

Value to add.

Returns

long

Value after the change.

And(long)

Performs a bitwise and operation on the current Value and the provided value and stores the result in Value.

public long And(long value)

Parameters

value long

Value to bitwise and.

Returns

long

Value before the change.

CompareExchange(long, long)

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

public long CompareExchange(long value, long comparand)

Parameters

value long

Value to set.

comparand long

Value used for Value comparison.

Returns

long

Value before the change.

CompareTo(InterlockedInt64)

Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.

[Pure]
public int CompareTo(InterlockedInt64 other)

Parameters

other InterlockedInt64

An object to compare with this instance.

Returns

int

A value that indicates the relative order of the objects being compared. The return value has these meanings:

Value Meaning
Less than zero This instance precedes other in the sort order.
Zero This instance occurs in the same position in the sort order as other.
Greater than zero This instance follows other in the sort order.

CompareTo(object?)

Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.

[Pure]
public int CompareTo(object? obj)

Parameters

obj object

An object to compare with this instance.

Returns

int

A value that indicates the relative order of the objects being compared. The return value has these meanings:

Value Meaning
Less than zero This instance precedes obj in the sort order.
Zero This instance occurs in the same position in the sort order as obj.
Greater than zero This instance follows obj in the sort order.

Exceptions

ArgumentException

obj is not the same type as this instance.

Decrement()

Decrements the current Value by 1.

public long Decrement()

Returns

long

Value after the change.

Equals(InterlockedInt64)

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

[Pure]
public bool Equals(InterlockedInt64 other)

Parameters

other InterlockedInt64

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(long)

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

public long Exchange(long value)

Parameters

value long

Value to set.

Returns

long

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.

Increment()

Increments the current Value by 1.

public long Increment()

Returns

long

Value after the change.

Or(long)

Performs a bitwise or operation on the current Value and the provided value and stores the result in Value.

public long Or(long value)

Parameters

value long

Value to bitwise or.

Returns

long

Value before the change.

Subtract(long)

Subtracts provided value from the current Value.

public long Subtract(long value)

Parameters

value long

Value to subtract.

Returns

long

Value after the change.

ToString()

Returns a string representation of this InterlockedInt64 instance.

[Pure]
public override string ToString()

Returns

string

String representation.

Write(long)

Sets Value to the provided value.

public bool Write(long value)

Parameters

value long

Value to set.

Returns

bool

true when value has changed, otherwise false.

Write(long, long)

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

public bool Write(long value, long expected)

Parameters

value long

Value to set.

expected long

Value used for Value comparison.

Returns

bool

true when value has changed, otherwise false.

Operators

operator ==(InterlockedInt64, InterlockedInt64)

Checks if a is equal to b.

public static bool operator ==(InterlockedInt64 a, InterlockedInt64 b)

Parameters

a InterlockedInt64

First operand.

b InterlockedInt64

Second operand.

Returns

bool

true when operands are equal, otherwise false.

operator >(InterlockedInt64, InterlockedInt64)

Checks if a is greater than b.

public static bool operator >(InterlockedInt64 a, InterlockedInt64 b)

Parameters

a InterlockedInt64

First operand.

b InterlockedInt64

Second operand.

Returns

bool

true when a is greater than b, otherwise false.

operator >=(InterlockedInt64, InterlockedInt64)

Checks if a is greater than or equal to b.

public static bool operator >=(InterlockedInt64 a, InterlockedInt64 b)

Parameters

a InterlockedInt64

First operand.

b InterlockedInt64

Second operand.

Returns

bool

true when a is greater than or equal to b, otherwise false.

operator !=(InterlockedInt64, InterlockedInt64)

Checks if a is not equal to b.

public static bool operator !=(InterlockedInt64 a, InterlockedInt64 b)

Parameters

a InterlockedInt64

First operand.

b InterlockedInt64

Second operand.

Returns

bool

true when operands are not equal, otherwise false.

operator <(InterlockedInt64, InterlockedInt64)

Checks if a is less than b.

public static bool operator <(InterlockedInt64 a, InterlockedInt64 b)

Parameters

a InterlockedInt64

First operand.

b InterlockedInt64

Second operand.

Returns

bool

true when a is less than b, otherwise false.

operator <=(InterlockedInt64, InterlockedInt64)

Checks if a is less than or equal to b.

public static bool operator <=(InterlockedInt64 a, InterlockedInt64 b)

Parameters

a InterlockedInt64

First operand.

b InterlockedInt64

Second operand.

Returns

bool

true when a is less than or equal to b, otherwise false.