github.com/nicocha30/gvisor-ligolo@v0.0.0-20230726075806-989fa2c0a413/pkg/atomicbitops/atomicbitops.go (about)

     1  // Copyright 2018 The gVisor Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  //go:build amd64 || arm64
    16  // +build amd64 arm64
    17  
    18  // Package atomicbitops provides extensions to the sync/atomic package.
    19  //
    20  // All read-modify-write operations implemented by this package have
    21  // acquire-release memory ordering (like sync/atomic).
    22  //
    23  // +checkalignedignore
    24  package atomicbitops
    25  
    26  // AndUint32 atomically applies bitwise AND operation to *addr with val.
    27  func AndUint32(addr *Uint32, val uint32) {
    28  	andUint32(&addr.value, val)
    29  }
    30  
    31  func andUint32(addr *uint32, val uint32)
    32  
    33  // OrUint32 atomically applies bitwise OR operation to *addr with val.
    34  func OrUint32(addr *Uint32, val uint32) {
    35  	orUint32(&addr.value, val)
    36  }
    37  
    38  func orUint32(addr *uint32, val uint32)
    39  
    40  // XorUint32 atomically applies bitwise XOR operation to *addr with val.
    41  func XorUint32(addr *Uint32, val uint32) {
    42  	xorUint32(&addr.value, val)
    43  }
    44  
    45  func xorUint32(addr *uint32, val uint32)
    46  
    47  // CompareAndSwapUint32 is like sync/atomic.CompareAndSwapUint32, but returns
    48  // the value previously stored at addr.
    49  func CompareAndSwapUint32(addr *Uint32, old, new uint32) uint32 {
    50  	return compareAndSwapUint32(&addr.value, old, new)
    51  }
    52  
    53  func compareAndSwapUint32(addr *uint32, old, new uint32) uint32
    54  
    55  // AndUint64 atomically applies bitwise AND operation to *addr with val.
    56  func AndUint64(addr *Uint64, val uint64) {
    57  	andUint64(&addr.value, val)
    58  }
    59  
    60  func andUint64(addr *uint64, val uint64)
    61  
    62  // OrUint64 atomically applies bitwise OR operation to *addr with val.
    63  func OrUint64(addr *Uint64, val uint64) {
    64  	orUint64(&addr.value, val)
    65  }
    66  
    67  func orUint64(addr *uint64, val uint64)
    68  
    69  // XorUint64 atomically applies bitwise XOR operation to *addr with val.
    70  func XorUint64(addr *Uint64, val uint64) {
    71  	xorUint64(&addr.value, val)
    72  }
    73  
    74  func xorUint64(addr *uint64, val uint64)
    75  
    76  // CompareAndSwapUint64 is like sync/atomic.CompareAndSwapUint64, but returns
    77  // the value previously stored at addr.
    78  func CompareAndSwapUint64(addr *Uint64, old, new uint64) uint64 {
    79  	return compareAndSwapUint64(&addr.value, old, new)
    80  }
    81  
    82  func compareAndSwapUint64(addr *uint64, old, new uint64) uint64