fix golint issues in core/syncx (#526)
This commit is contained in:
@@ -2,18 +2,22 @@ package syncx
|
||||
|
||||
import "sync/atomic"
|
||||
|
||||
// An AtomicBool is an atomic implementation for boolean values.
|
||||
type AtomicBool uint32
|
||||
|
||||
// NewAtomicBool returns an AtomicBool.
|
||||
func NewAtomicBool() *AtomicBool {
|
||||
return new(AtomicBool)
|
||||
}
|
||||
|
||||
// ForAtomicBool returns an AtomicBool with given val.
|
||||
func ForAtomicBool(val bool) *AtomicBool {
|
||||
b := NewAtomicBool()
|
||||
b.Set(val)
|
||||
return b
|
||||
}
|
||||
|
||||
// CompareAndSwap compares current value with given old, if equals, set to given val.
|
||||
func (b *AtomicBool) CompareAndSwap(old, val bool) bool {
|
||||
var ov, nv uint32
|
||||
if old {
|
||||
@@ -25,6 +29,7 @@ func (b *AtomicBool) CompareAndSwap(old, val bool) bool {
|
||||
return atomic.CompareAndSwapUint32((*uint32)(b), ov, nv)
|
||||
}
|
||||
|
||||
// Set sets the value to v.
|
||||
func (b *AtomicBool) Set(v bool) {
|
||||
if v {
|
||||
atomic.StoreUint32((*uint32)(b), 1)
|
||||
@@ -33,6 +38,7 @@ func (b *AtomicBool) Set(v bool) {
|
||||
}
|
||||
}
|
||||
|
||||
// True returns true if current value is true.
|
||||
func (b *AtomicBool) True() bool {
|
||||
return atomic.LoadUint32((*uint32)(b)) == 1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user