This change adds the Bool type, a convenient wrapper around Uint8 for
atomic bool values.
Change-Id: I86127d6f213b730d6999db5718ca1a5af0c5b538
Reviewed-on: https://go-review.googlesource.com/c/go/+/393395
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: Austin Clements <austin@google.com>
Trust: Michael Knyszek <mknyszek@google.com>
Or8(&u.value, value)
}
+// Bool is an atomically accessed bool value.
+//
+// A Bool must not be copied.
+type Bool struct {
+ // Inherits noCopy from Uint8.
+ u Uint8
+}
+
+// Load accesses and returns the value atomically.
+func (b *Bool) Load() bool {
+ return b.u.Load() != 0
+}
+
+// Store updates the value atomically.
+func (b *Bool) Store(value bool) {
+ s := uint8(0)
+ if value {
+ s = 1
+ }
+ b.u.Store(s)
+}
+
// Uint32 is an atomically accessed uint32 value.
//
// A Uint32 must not be copied.
//
// A Float64 must not be copied.
type Float64 struct {
+ // Inherits noCopy from Uint64.
u Uint64
}