mirror of https://github.com/tevino/abool.git
Refine comments
This commit is contained in:
parent
df1d8a392d
commit
6662858d93
12
bool.go
12
bool.go
|
@ -18,27 +18,29 @@ func NewBool(ok bool) *AtomicBool {
|
|||
return ab
|
||||
}
|
||||
|
||||
// AtomicBool is a atomic boolean
|
||||
// AtomicBool is an atomic Boolean
|
||||
// Its methods are all atomic, thus safe to be called by
|
||||
// multiple goroutines simultaneously
|
||||
// Note: When embedding into a struct, one should always use
|
||||
// *AtomicBool to avoid copy
|
||||
type AtomicBool int32
|
||||
|
||||
// Set sets the bool to true
|
||||
// Set sets the Boolean to true
|
||||
func (ab *AtomicBool) Set() {
|
||||
atomic.StoreInt32((*int32)(ab), 1)
|
||||
}
|
||||
|
||||
// UnSet sets the bool to false
|
||||
// UnSet sets the Boolean to false
|
||||
func (ab *AtomicBool) UnSet() {
|
||||
atomic.StoreInt32((*int32)(ab), 0)
|
||||
}
|
||||
|
||||
// IsSet returns whether the bool is true
|
||||
// IsSet returns whether the Boolean is true
|
||||
func (ab *AtomicBool) IsSet() bool {
|
||||
return atomic.LoadInt32((*int32)(ab)) == 1
|
||||
}
|
||||
|
||||
// SetTo sets the boolean with given bool
|
||||
// SetTo sets the boolean with given Boolean
|
||||
func (ab *AtomicBool) SetTo(yes bool) {
|
||||
if yes {
|
||||
atomic.StoreInt32((*int32)(ab), 1)
|
||||
|
|
Loading…
Reference in New Issue