aboutsummaryrefslogtreecommitdiffstats
path: root/src/misc.go
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/misc.go19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/misc.go b/src/misc.go
index fc75c0d..d93849e 100644
--- a/src/misc.go
+++ b/src/misc.go
@@ -1,6 +1,7 @@
package main
import (
+ "sync/atomic"
"time"
)
@@ -8,10 +9,26 @@ import (
* (since booleans are not natively supported by sync/atomic)
*/
const (
- AtomicFalse = iota
+ AtomicFalse = int32(iota)
AtomicTrue
)
+type AtomicBool struct {
+ flag int32
+}
+
+func (a *AtomicBool) Get() bool {
+ return atomic.LoadInt32(&a.flag) == AtomicTrue
+}
+
+func (a *AtomicBool) Set(val bool) {
+ flag := AtomicFalse
+ if val {
+ flag = AtomicTrue
+ }
+ atomic.StoreInt32(&a.flag, flag)
+}
+
func min(a uint, b uint) uint {
if a > b {
return b