Struct AtomicBoolean
Represents atomic boolean.
Inherited Members
Namespace: DotNext.Threading
Assembly: DotNext.dll
Syntax
[Serializable]
public struct AtomicBoolean : IEquatable<bool>, ISerializable
Constructors
| Improve this Doc View SourceAtomicBoolean(Boolean)
Initializes a new atomic boolean container with initial value.
Declaration
public AtomicBoolean(bool value)
Parameters
| Type | Name | Description |
|---|---|---|
| Boolean | value | Initial value of the atomic boolean. |
Properties
| Improve this Doc View SourceValue
Gets or sets boolean value in volatile manner.
Declaration
public bool Value { get; set; }
Property Value
| Type | Description |
|---|---|
| Boolean |
Methods
| Improve this Doc View SourceAccumulateAndGet(Boolean, ValueFunc<Boolean, Boolean, Boolean>)
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 bool AccumulateAndGet(bool x, in ValueFunc<bool, bool, bool> accumulator)
Parameters
| Type | Name | Description |
|---|---|---|
| Boolean | x | Accumulator operand. |
| ValueFunc<Boolean, Boolean, Boolean> | accumulator | A side-effect-free function of two arguments. |
Returns
| Type | Description |
|---|---|
| Boolean | 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(Boolean, Func<Boolean, Boolean, Boolean>)
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 bool AccumulateAndGet(bool x, Func<bool, bool, bool> accumulator)
Parameters
| Type | Name | Description |
|---|---|---|
| Boolean | x | Accumulator operand. |
| Func<Boolean, Boolean, Boolean> | accumulator | A side-effect-free function of two arguments. |
Returns
| Type | Description |
|---|---|
| Boolean | 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(Boolean, Boolean)
Atomically sets referenced value to the given updated value if the current value == the expected value.
Declaration
public bool CompareAndSet(bool expected, bool update)
Parameters
| Type | Name | Description |
|---|---|---|
| Boolean | expected | The expected value. |
| Boolean | 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(Boolean, Boolean)
Atomically sets referenced value to the given updated value if the current value == the expected value.
Declaration
public bool CompareExchange(bool update, bool expected)
Parameters
| Type | Name | Description |
|---|---|---|
| Boolean | update | The new value. |
| Boolean | expected | The expected value. |
Returns
| Type | Description |
|---|---|
| Boolean | The original value. |
Equals(Boolean)
Determines whether stored value is equal to value passed as argument.
Declaration
public bool Equals(bool other)
Parameters
| Type | Name | Description |
|---|---|---|
| Boolean | other | Other value to compare. |
Returns
| Type | Description |
|---|---|
| Boolean | true, if stored value is equal to other value; otherwise, false. |
Equals(Object)
Determines whether stored value is equal to value as the passed argument.
Declaration
public override bool Equals(object other)
Parameters
| Type | Name | Description |
|---|---|---|
| Object | other | Other value to compare. |
Returns
| Type | Description |
|---|---|
| Boolean | true, if stored value is equal to other value; otherwise, false. |
Overrides
| Improve this Doc View SourceFalseToTrue()
Atomically sets true value if the current value is false.
Declaration
public bool FalseToTrue()
Returns
| Type | Description |
|---|---|
| Boolean | true if current value is modified successfully; otherwise, false. |
GetAndAccumulate(Boolean, ValueFunc<Boolean, Boolean, Boolean>)
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 bool GetAndAccumulate(bool x, in ValueFunc<bool, bool, bool> accumulator)
Parameters
| Type | Name | Description |
|---|---|---|
| Boolean | x | Accumulator operand. |
| ValueFunc<Boolean, Boolean, Boolean> | accumulator | A side-effect-free function of two arguments. |
Returns
| Type | Description |
|---|---|
| Boolean | 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(Boolean, Func<Boolean, Boolean, Boolean>)
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 bool GetAndAccumulate(bool x, Func<bool, bool, bool> accumulator)
Parameters
| Type | Name | Description |
|---|---|---|
| Boolean | x | Accumulator operand. |
| Func<Boolean, Boolean, Boolean> | accumulator | A side-effect-free function of two arguments. |
Returns
| Type | Description |
|---|---|
| Boolean | The original value. |
Remarks
The function is applied with the current value as its first argument, and the given update as the second argument.
GetAndNegate()
Negates currently stored value atomically.
Declaration
public bool GetAndNegate()
Returns
| Type | Description |
|---|---|
| Boolean | The original value before negation. |
GetAndSet(Boolean)
Modifies the current value atomically.
Declaration
public bool GetAndSet(bool update)
Parameters
| Type | Name | Description |
|---|---|---|
| Boolean | update | A new value to be stored into this container. |
Returns
| Type | Description |
|---|---|
| Boolean | Original value before modification. |
GetAndUpdate(ValueFunc<Boolean, Boolean>)
Atomically updates the stored value with the results of applying the given function, returning the original value.
Declaration
public bool GetAndUpdate(in ValueFunc<bool, bool> updater)
Parameters
| Type | Name | Description |
|---|---|---|
| ValueFunc<Boolean, Boolean> | updater | A side-effect-free function. |
Returns
| Type | Description |
|---|---|
| Boolean | The original value. |
GetAndUpdate(Func<Boolean, Boolean>)
Atomically updates the stored value with the results of applying the given function, returning the original value.
Declaration
public bool GetAndUpdate(Func<bool, bool> updater)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<Boolean, Boolean> | updater | A side-effect-free function. |
Returns
| Type | Description |
|---|---|
| Boolean | 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 boolean value. |
Overrides
| Improve this Doc View SourceNegateAndGet()
Negates currently stored value atomically.
Declaration
public bool NegateAndGet()
Returns
| Type | Description |
|---|---|
| Boolean | Negation result. |
SetAndGet(Boolean)
Modifies the current value atomically.
Declaration
public bool SetAndGet(bool update)
Parameters
| Type | Name | Description |
|---|---|---|
| Boolean | update | A new value to be stored into this container. |
Returns
| Type | Description |
|---|---|
| Boolean | A new value passed as argument. |
ToString()
Returns stored boolean value in the form of String.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| String | Textual representation of stored boolean value. |
Overrides
| Improve this Doc View SourceTrueToFalse()
Atomically sets false value if the current value is true.
Declaration
public bool TrueToFalse()
Returns
| Type | Description |
|---|---|
| Boolean | true if current value is modified successfully; otherwise, false. |
UpdateAndGet(ValueFunc<Boolean, Boolean>)
Atomically updates the stored value with the results of applying the given function, returning the updated value.
Declaration
public bool UpdateAndGet(in ValueFunc<bool, bool> updater)
Parameters
| Type | Name | Description |
|---|---|---|
| ValueFunc<Boolean, Boolean> | updater | A side-effect-free function. |
Returns
| Type | Description |
|---|---|
| Boolean | The updated value. |
UpdateAndGet(Func<Boolean, Boolean>)
Atomically updates the stored value with the results of applying the given function, returning the updated value.
Declaration
public bool UpdateAndGet(Func<bool, bool> updater)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<Boolean, Boolean> | updater | A side-effect-free function. |
Returns
| Type | Description |
|---|---|
| Boolean | The updated value. |
Explicit Interface Implementations
| Improve this Doc View SourceISerializable.GetObjectData(SerializationInfo, StreamingContext)
Declaration
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
Parameters
| Type | Name | Description |
|---|---|---|
| SerializationInfo | info | |
| StreamingContext | context |