RaspberryIO/Unosquare.Swan.Lite/AtomicBoolean.cs

24 lines
804 B
C#
Raw Normal View History

2019-12-04 17:10:06 +01:00
using System;
using Unosquare.Swan.Abstractions;
namespace Unosquare.Swan {
/// <summary>
/// Fast, atomic boolean combining interlocked to write value and volatile to read values.
/// </summary>
public sealed class AtomicBoolean : AtomicTypeBase<Boolean> {
2019-02-17 14:08:57 +01:00
/// <summary>
2019-12-04 17:10:06 +01:00
/// Initializes a new instance of the <see cref="AtomicBoolean"/> class.
2019-02-17 14:08:57 +01:00
/// </summary>
2019-12-04 17:10:06 +01:00
/// <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;
}
2019-02-17 14:08:57 +01:00
}