RaspberryIO_26/Swan.Lite/Threading/AtomicDouble.cs

22 lines
824 B
C#
Raw Normal View History

2019-12-04 18:57:18 +01:00
using System;
2019-12-08 19:54:52 +01:00
namespace Swan.Threading {
/// <summary>
/// Fast, atomic double combining interlocked to write value and volatile to read values.
/// </summary>
public sealed class AtomicDouble : AtomicTypeBase<Double> {
2019-12-04 18:57:18 +01:00
/// <summary>
2019-12-08 19:54:52 +01:00
/// Initializes a new instance of the <see cref="AtomicDouble"/> class.
2019-12-04 18:57:18 +01:00
/// </summary>
2019-12-08 19:54:52 +01:00
/// <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);
}
2019-12-04 18:57:18 +01:00
}