gitee.com/go-spring2/spring-base@v1.1.3/atomic/uintptr.go (about)

     1  /*
     2   * Copyright 2012-2019 the original author or authors.
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *      https://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  package atomic
    18  
    19  import (
    20  	"sync/atomic"
    21  )
    22  
    23  // An Uintptr is an atomic uintptr value.
    24  type Uintptr struct {
    25  	_ nocopy
    26  	v uintptr
    27  }
    28  
    29  // Add atomically adds delta to x and returns the new value.
    30  func (x *Uintptr) Add(delta uintptr) (new uintptr) {
    31  	return atomic.AddUintptr(&x.v, delta)
    32  }
    33  
    34  // Load atomically loads and returns the value stored in x.
    35  func (x *Uintptr) Load() (val uintptr) {
    36  	return atomic.LoadUintptr(&x.v)
    37  }
    38  
    39  // Store atomically stores val into x.
    40  func (x *Uintptr) Store(val uintptr) {
    41  	atomic.StoreUintptr(&x.v, val)
    42  }
    43  
    44  // Swap atomically stores new into x and returns the old value.
    45  func (x *Uintptr) Swap(new uintptr) (old uintptr) {
    46  	return atomic.SwapUintptr(&x.v, new)
    47  }
    48  
    49  // CompareAndSwap executes the compare-and-swap operation for x.
    50  func (x *Uintptr) CompareAndSwap(old, new uintptr) (swapped bool) {
    51  	return atomic.CompareAndSwapUintptr(&x.v, old, new)
    52  }