github.com/voedger/voedger@v0.0.0-20240520144910-273e84102129/pkg/metrics/types.go (about) 1 /* 2 * Copyright (c) 2021-present unTill Pro, Ltd. 3 * 4 * @author Michael Saigachenko 5 */ 6 7 package imetrics 8 9 import ( 10 "math" 11 "sync/atomic" 12 "unsafe" 13 ) 14 15 type MetricsFactory func() IMetrics 16 17 type MetricValue float64 18 19 func (m *MetricValue) Increase(delta float64) { 20 var swapped bool 21 ptr := (*uint64)(unsafe.Pointer(m)) 22 for !swapped { 23 oldValue := math.Float64frombits(atomic.LoadUint64(ptr)) 24 newValue := oldValue + delta 25 swapped = atomic.CompareAndSwapUint64( 26 ptr, 27 math.Float64bits(oldValue), 28 math.Float64bits(newValue), 29 ) 30 } 31 }