mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-22 13:05:36 +03:00
20 lines
378 B
Go
20 lines
378 B
Go
package dnsfilter
|
|
|
|
import (
|
|
"sync/atomic"
|
|
)
|
|
|
|
func updateMax(valuePtr *int64, maxPtr *int64) {
|
|
for {
|
|
current := atomic.LoadInt64(valuePtr)
|
|
max := atomic.LoadInt64(maxPtr)
|
|
if current <= max {
|
|
break
|
|
}
|
|
swapped := atomic.CompareAndSwapInt64(maxPtr, max, current)
|
|
if swapped {
|
|
break
|
|
}
|
|
// swapping failed because value has changed after reading, try again
|
|
}
|
|
}
|