github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/util/syncutil/atomic.go (about) 1 // Copyright 2017 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package syncutil 12 13 import ( 14 "math" 15 "sync/atomic" 16 ) 17 18 // AtomicFloat64 mimics the atomic types in the sync/atomic standard library, 19 // but for the float64 type. If you'd like to implement additional methods, 20 // consider checking out the expvar Float type for guidance: 21 // https://golang.org/src/expvar/expvar.go?s=2188:2222#L69 22 type AtomicFloat64 uint64 23 24 // StoreFloat64 atomically stores a float64 value into the provided address. 25 func StoreFloat64(addr *AtomicFloat64, val float64) { 26 atomic.StoreUint64((*uint64)(addr), math.Float64bits(val)) 27 } 28 29 // LoadFloat64 atomically loads tha float64 value from the provided address. 30 func LoadFloat64(addr *AtomicFloat64) (val float64) { 31 return math.Float64frombits(atomic.LoadUint64((*uint64)(addr))) 32 }