...
1 package internal
2
3 import (
4 "sync/atomic"
5 )
6
7
8
9
10 type AtomicBoolean struct {
11 value int32
12 }
13
14
15 func (a *AtomicBoolean) Get() bool {
16 return int32ToBoolean(atomic.LoadInt32(&a.value))
17 }
18
19
20 func (a *AtomicBoolean) Set(value bool) {
21 atomic.StoreInt32(&a.value, booleanToInt32(value))
22 }
23
24
25 func (a *AtomicBoolean) GetAndSet(value bool) bool {
26 return int32ToBoolean(atomic.SwapInt32(&a.value, booleanToInt32(value)))
27 }
28
29 func booleanToInt32(value bool) int32 {
30 if value {
31 return 1
32 }
33 return 0
34 }
35
36 func int32ToBoolean(value int32) bool {
37 return value != 0
38 }
39
View as plain text