github.com/tursom/GoCollections@v0.3.10/lang/atomic/Bool.go (about) 1 /* 2 * Copyright (c) 2022 tursom. All rights reserved. 3 * Use of this source code is governed by a GPL-3 4 * license that can be found in the LICENSE file. 5 */ 6 7 package atomic 8 9 type Bool Int32 10 11 func (v *Bool) Load() (val bool) { 12 return (*Int32)(v).Load() != 0 13 } 14 15 func (v *Bool) Store(val bool) { 16 if val { 17 (*Int32)(v).Store(1) 18 } else { 19 (*Int32)(v).Store(0) 20 } 21 } 22 23 func (v *Bool) Swap(new bool) (old bool) { 24 n := int32(0) 25 if new { 26 n = 1 27 } 28 return (*Int32)(v).Swap(n) != 0 29 } 30 31 func (v *Bool) CompareAndSwap(old, new bool) (swapped bool) { 32 o := int32(0) 33 if old { 34 o = 1 35 } 36 n := int32(0) 37 if new { 38 n = 1 39 } 40 return (*Int32)(v).CompareAndSwap(o, n) 41 }