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