github.com/tursom/GoCollections@v0.3.10/lang/atomic/Int32.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 import ( 10 "strconv" 11 "sync/atomic" 12 13 "github.com/tursom/GoCollections/lang" 14 ) 15 16 type Int32 int32 17 18 func (v *Int32) P() *int32 { 19 return (*int32)(v) 20 } 21 22 func (v *Int32) Load() (val int32) { 23 return atomic.LoadInt32(v.P()) 24 } 25 26 func (v *Int32) Store(val int32) { 27 atomic.StoreInt32(v.P(), val) 28 } 29 30 func (v *Int32) Swap(new int32) (old int32) { 31 return atomic.SwapInt32(v.P(), new) 32 } 33 34 func (v *Int32) CompareAndSwap(old, new int32) (swapped bool) { 35 return atomic.CompareAndSwapInt32(v.P(), old, new) 36 } 37 38 func (v *Int32) Add(i int32) (new int32) { 39 return atomic.AddInt32(v.P(), i) 40 } 41 42 func (v *Int32) BitLength() int { 43 return 32 44 } 45 46 func (v *Int32) SetBit(bit int, up bool) bool { 47 return SetBit(CompareAndSwapInt32, v.P(), bit, up) 48 } 49 50 func (v *Int32) CompareAndSwapBit(bit int, old, new bool) bool { 51 return CompareAndSwapBit(CompareAndSwapInt32, v.P(), bit, old, new) 52 } 53 54 func (v *Int32) String() string { 55 return strconv.FormatInt(int64(*v), 10) 56 } 57 58 func (v *Int32) AsObject() lang.Object { 59 return v 60 } 61 62 func (v *Int32) Equals(o lang.Object) bool { 63 return lang.EqualsInt32(v, o) 64 } 65 66 func (v *Int32) HashCode() int32 { 67 return lang.Hash32(v) 68 } 69 70 func (v *Int32) ToInt64() lang.Int64 { 71 return lang.Int64(*v) 72 } 73 74 func (v *Int32) ToUInt64() lang.UInt64 { 75 return lang.UInt64(*v) 76 } 77 78 func (v *Int32) ToFloat64() lang.Float64 { 79 return lang.Float64(*v) 80 }