mirror of
https://github.com/HDT3213/godis.git
synced 2025-10-07 01:32:56 +08:00
21 lines
397 B
Go
21 lines
397 B
Go
package atomic
|
|
|
|
import "sync/atomic"
|
|
|
|
// Boolean is a boolean value, all actions of it is atomic
|
|
type Boolean uint32
|
|
|
|
// Get reads the value atomically
|
|
func (b *Boolean) Get() bool {
|
|
return atomic.LoadUint32((*uint32)(b)) != 0
|
|
}
|
|
|
|
// Set writes the value atomically
|
|
func (b *Boolean) Set(v bool) {
|
|
if v {
|
|
atomic.StoreUint32((*uint32)(b), 1)
|
|
} else {
|
|
atomic.StoreUint32((*uint32)(b), 0)
|
|
}
|
|
}
|