Style: use atomic CompareAndSwap (#151)

This commit is contained in:
beyondkmp 2019-03-26 23:48:03 +08:00 committed by Dreamacro
parent 791d72e05b
commit d1f6886558

View File

@ -92,7 +92,7 @@ func (u *URLTest) fallback() {
} }
func (u *URLTest) speedTest() { func (u *URLTest) speedTest() {
if atomic.AddInt32(&u.once, 1) != 1 { if atomic.CompareAndSwapInt32(&u.once, 0, 1) {
return return
} }
defer atomic.StoreInt32(&u.once, 0) defer atomic.StoreInt32(&u.once, 0)