github.com/tursom/GoCollections@v0.3.10/lang/atomic/Uintptr.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 "sync/atomic" 11 12 "github.com/tursom/GoCollections/unsafe" 13 ) 14 15 type ( 16 Uintptr uintptr 17 TypedUintptr[T any] Uintptr 18 ) 19 20 func (p *Uintptr) Raw() uintptr { 21 return uintptr(*p) 22 } 23 24 func (p *Uintptr) RawP() *uintptr { 25 return (*uintptr)(p) 26 } 27 28 func (p *Uintptr) AsPointer() Pointer { 29 return Pointer(p) 30 } 31 32 func (p *Uintptr) AsPPointer() PPointer { 33 return PPointer(p.AsPointer()) 34 } 35 func (p *Uintptr) Load() (val Uintptr) { 36 return Uintptr(atomic.LoadUintptr((*uintptr)(p))) 37 } 38 39 func (p *Uintptr) Store(val Uintptr) { 40 atomic.StoreUintptr((*uintptr)(p), uintptr(val)) 41 } 42 43 func (p *Uintptr) Swap(new Uintptr) (old Uintptr) { 44 return Uintptr(atomic.SwapUintptr((*uintptr)(p), uintptr(new))) 45 } 46 47 func (p *Uintptr) CompareAndSwap(old, new Uintptr) (swapped bool) { 48 return atomic.CompareAndSwapUintptr((*uintptr)(p), uintptr(old), uintptr(new)) 49 } 50 51 func (p *TypedUintptr[T]) Raw() uintptr { 52 return uintptr(*p) 53 } 54 55 func (p *TypedUintptr[T]) RawP() *uintptr { 56 return (*uintptr)(p) 57 } 58 59 func (p *TypedUintptr[T]) AsPointer() Pointer { 60 return Pointer(p) 61 } 62 63 func (p *TypedUintptr[T]) AsPPointer() PPointer { 64 return PPointer(p.AsPointer()) 65 } 66 67 func (tp *TypedUintptr[T]) AsReference() *Reference[T] { 68 return unsafe.ForceCast[Reference[T]](Pointer(tp)) 69 } 70 71 func (tp *TypedUintptr[T]) Uintptr() Uintptr { 72 return Uintptr(*tp) 73 } 74 75 func (tp *TypedUintptr[T]) PUintptr() *Uintptr { 76 return (*Uintptr)(tp) 77 } 78 79 func (tp *TypedUintptr[T]) Load() TypedUintptr[T] { 80 return TypedUintptr[T](atomic.LoadUintptr((*uintptr)(tp))) 81 } 82 83 func (tp *TypedUintptr[T]) Store(val TypedUintptr[T]) { 84 atomic.StoreUintptr((*uintptr)(tp), uintptr(val)) 85 } 86 87 func (tp *TypedUintptr[T]) Swap(new TypedUintptr[T]) (old TypedUintptr[T]) { 88 return TypedUintptr[T](atomic.SwapUintptr((*uintptr)(tp), uintptr(new))) 89 } 90 91 func (tp *TypedUintptr[T]) CompareAndSwap(old, new TypedUintptr[T]) (swapped bool) { 92 return atomic.CompareAndSwapUintptr((*uintptr)(tp), uintptr(old), uintptr(new)) 93 }