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