RaspberryIO/Unosquare.Swan.Lite/AtomicDouble.cs
2019-12-04 17:10:06 +01:00

26 lines
889 B
C#

using System;
using Unosquare.Swan.Abstractions;
namespace Unosquare.Swan {
/// <summary>
/// Fast, atomic double combining interlocked to write value and volatile to read values.
/// </summary>
public sealed class AtomicDouble : AtomicTypeBase<Double> {
/// <summary>
/// Initializes a new instance of the <see cref="AtomicDouble"/> class.
/// </summary>
/// <param name="initialValue">if set to <c>true</c> [initial value].</param>
public AtomicDouble(Double initialValue = default)
: base(BitConverter.DoubleToInt64Bits(initialValue)) {
// placeholder
}
/// <inheritdoc/>
protected override Double FromLong(Int64 backingValue) =>
BitConverter.Int64BitsToDouble(backingValue);
/// <inheritdoc/>
protected override Int64 ToLong(Double value) =>
BitConverter.DoubleToInt64Bits(value);
}
}