This commit is contained in:
aozhiwei 2024-07-23 11:42:41 +08:00
parent db5e615704
commit ccfa6c4f99

View File

@ -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)
}
}