diff --git a/sync.go b/sync.go index d559d34..470d0b0 100644 --- a/sync.go +++ b/sync.go @@ -2,6 +2,7 @@ package q5 import ( "sync" + "sync/atomic" ) type ConcurrentMap[T1 string | int | int32 | int64, T2 any] struct { @@ -69,3 +70,10 @@ func (this *ConcurrentMap[T1, T2]) Swap(key T1, value T2) (*T2, bool) { return nil, loaded } } + +func AtomicStoreInt64WhenGreater(srcVal *int64, trgVal *int64) { + tmpVal := atomic.LoadInt64(srcVal) + if tmpVal > *trgVal { + atomic.StoreInt64(trgVal, tmpVal) + } +}