_min = double.PositiveInfinity;
_max = double.NegativeInfinity;
- InitializeBuffer();
+ var bufferedValues = new double[BufferedSize];
+ for (int i = 0; i < bufferedValues.Length; i++)
+ {
+ bufferedValues[i] = UnusedBufferSlotValue;
+ }
+ Volatile.Write(ref _bufferedValues, bufferedValues);
+
Publish();
}
// Values buffering
private const int BufferedSize = 10;
private const double UnusedBufferSlotValue = double.NegativeInfinity;
- private volatile double[] _bufferedValues;
+ private readonly double[] _bufferedValues;
private volatile int _bufferedValuesIndex;
- [MemberNotNull(nameof(_bufferedValues))]
- private void InitializeBuffer()
- {
- _bufferedValues = new double[BufferedSize];
- for (int i = 0; i < _bufferedValues.Length; i++)
- {
- _bufferedValues[i] = UnusedBufferSlotValue;
- }
- }
-
private void Enqueue(double value)
{
// It is possible that two threads read the same bufferedValuesIndex, but only one will be able to write the slot, so that is okay.