fix potential race (#86)

This commit is contained in:
UUBulb
2024-11-18 20:51:15 +08:00
committed by GitHub
parent af41e4d843
commit 32481e2b6f
2 changed files with 30 additions and 12 deletions
+3 -3
View File
@@ -57,7 +57,7 @@ var statDataFetchAttempts = map[uint8]uint8{
}
var (
updateTempStatus = new(atomic.Int32)
updateTempStatus = new(atomic.Bool)
)
func InitConfig(cfg *model.AgentConfig) {
@@ -236,10 +236,10 @@ func getConns() (tcpConnCount, udpConnCount uint64) {
}
func updateTemperatureStat() {
if !updateTempStatus.CompareAndSwap(0, 1) {
if !updateTempStatus.CompareAndSwap(false, true) {
return
}
defer updateTempStatus.Store(0)
defer updateTempStatus.Store(false)
stat := tryStat(context.Background(), Temperatures, temperature.GetState)
temperatureStat = stat