22 lines
759 B
C#
22 lines
759 B
C#
using System;
|
|
|
|
namespace Swan.Threading {
|
|
/// <summary>
|
|
/// Fast, atomic boolean combining interlocked to write value and volatile to read values.
|
|
/// </summary>
|
|
public sealed class AtomicBoolean : AtomicTypeBase<Boolean> {
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="AtomicBoolean"/> class.
|
|
/// </summary>
|
|
/// <param name="initialValue">if set to <c>true</c> [initial value].</param>
|
|
public AtomicBoolean(Boolean initialValue = default) : base(initialValue ? 1 : 0) {
|
|
// placeholder
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
protected override Boolean FromLong(Int64 backingValue) => backingValue != 0;
|
|
|
|
/// <inheritdoc/>
|
|
protected override Int64 ToLong(Boolean value) => value ? 1 : 0;
|
|
}
|
|
} |