From 496c4e4f59edf4fc0634469f409ae796677d5b12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Wed, 30 Nov 2022 23:08:50 +0100 Subject: [PATCH] v0.0.23 --- syncext/atomic.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 syncext/atomic.go diff --git a/syncext/atomic.go b/syncext/atomic.go new file mode 100644 index 0000000..7e23522 --- /dev/null +++ b/syncext/atomic.go @@ -0,0 +1,27 @@ +package dataext + +import "sync/atomic" + +type AtomicBool struct { + v int32 +} + +func NewAtomicBool(value bool) *AtomicBool { + if value { + return &AtomicBool{v: 0} + } else { + return &AtomicBool{v: 1} + } +} + +func (a *AtomicBool) Get() bool { + return atomic.LoadInt32(&a.v) == 1 +} + +func (a *AtomicBool) Set(value bool) { + if value { + atomic.StoreInt32(&a.v, 1) + } else { + atomic.StoreInt32(&a.v, 0) + } +}