fix golint issues in core/syncx (#526)

This commit is contained in:
Kevin Wan
2021-02-28 16:16:22 +08:00
committed by GitHub
parent f02711a9cb
commit 490241d639
18 changed files with 73 additions and 2 deletions

View File

@@ -2,14 +2,17 @@ package syncx
import "sync/atomic"
// A OnceGuard is used to make sure a resouce can be taken once.
type OnceGuard struct {
done uint32
}
// Taken checks if the resource is taken.
func (og *OnceGuard) Taken() bool {
return atomic.LoadUint32(&og.done) == 1
}
// Take takes the resource, returns true on success, false for otherwise.
func (og *OnceGuard) Take() bool {
return atomic.CompareAndSwapUint32(&og.done, 0, 1)
}