@@ -394,7 +394,7 @@ internal void Update(long number)
394394 case AggregationType . LongSumIncomingCumulative :
395395 case AggregationType . LongGauge :
396396 {
397- Volatile . Write ( ref this . runningValue . AsLong , number ) ;
397+ Interlocked . Exchange ( ref this . runningValue . AsLong , number ) ;
398398 break ;
399399 }
400400
@@ -451,7 +451,7 @@ internal void UpdateWithExemplar(long number, ReadOnlySpan<KeyValuePair<string,
451451 case AggregationType . LongSumIncomingCumulative :
452452 case AggregationType . LongGauge :
453453 {
454- Volatile . Write ( ref this . runningValue . AsLong , number ) ;
454+ Interlocked . Exchange ( ref this . runningValue . AsLong , number ) ;
455455 break ;
456456 }
457457
@@ -510,7 +510,7 @@ internal void Update(double number)
510510 case AggregationType . DoubleSumIncomingCumulative :
511511 case AggregationType . DoubleGauge :
512512 {
513- Volatile . Write ( ref this . runningValue . AsDouble , number ) ;
513+ Interlocked . Exchange ( ref this . runningValue . AsDouble , number ) ;
514514 break ;
515515 }
516516
@@ -567,7 +567,7 @@ internal void UpdateWithExemplar(double number, ReadOnlySpan<KeyValuePair<string
567567 case AggregationType . DoubleSumIncomingCumulative :
568568 case AggregationType . DoubleGauge :
569569 {
570- Volatile . Write ( ref this . runningValue . AsDouble , number ) ;
570+ Interlocked . Exchange ( ref this . runningValue . AsDouble , number ) ;
571571 break ;
572572 }
573573
@@ -622,7 +622,7 @@ internal void TakeSnapshot(bool outputDelta)
622622 {
623623 if ( outputDelta )
624624 {
625- long initValue = Volatile . Read ( ref this . runningValue . AsLong ) ;
625+ long initValue = Interlocked . Read ( ref this . runningValue . AsLong ) ;
626626 this . snapshotValue . AsLong = initValue - this . deltaLastValue . AsLong ;
627627 this . deltaLastValue . AsLong = initValue ;
628628 this . MetricPointStatus = MetricPointStatus . NoCollectPending ;
@@ -636,7 +636,7 @@ internal void TakeSnapshot(bool outputDelta)
636636 }
637637 else
638638 {
639- this . snapshotValue . AsLong = Volatile . Read ( ref this . runningValue . AsLong ) ;
639+ this . snapshotValue . AsLong = Interlocked . Read ( ref this . runningValue . AsLong ) ;
640640 }
641641
642642 break ;
@@ -647,7 +647,7 @@ internal void TakeSnapshot(bool outputDelta)
647647 {
648648 if ( outputDelta )
649649 {
650- double initValue = Volatile . Read ( ref this . runningValue . AsDouble ) ;
650+ double initValue = InterlockedHelper . Read ( ref this . runningValue . AsDouble ) ;
651651 this . snapshotValue . AsDouble = initValue - this . deltaLastValue . AsDouble ;
652652 this . deltaLastValue . AsDouble = initValue ;
653653 this . MetricPointStatus = MetricPointStatus . NoCollectPending ;
@@ -661,15 +661,15 @@ internal void TakeSnapshot(bool outputDelta)
661661 }
662662 else
663663 {
664- this . snapshotValue . AsDouble = Volatile . Read ( ref this . runningValue . AsDouble ) ;
664+ this . snapshotValue . AsDouble = InterlockedHelper . Read ( ref this . runningValue . AsDouble ) ;
665665 }
666666
667667 break ;
668668 }
669669
670670 case AggregationType . LongGauge :
671671 {
672- this . snapshotValue . AsLong = Volatile . Read ( ref this . runningValue . AsLong ) ;
672+ this . snapshotValue . AsLong = Interlocked . Read ( ref this . runningValue . AsLong ) ;
673673 this . MetricPointStatus = MetricPointStatus . NoCollectPending ;
674674
675675 // Check again if value got updated, if yes reset status.
@@ -684,7 +684,7 @@ internal void TakeSnapshot(bool outputDelta)
684684
685685 case AggregationType . DoubleGauge :
686686 {
687- this . snapshotValue . AsDouble = Volatile . Read ( ref this . runningValue . AsDouble ) ;
687+ this . snapshotValue . AsDouble = InterlockedHelper . Read ( ref this . runningValue . AsDouble ) ;
688688 this . MetricPointStatus = MetricPointStatus . NoCollectPending ;
689689
690690 // Check again if value got updated, if yes reset status.
0 commit comments