...

Source file src/internal/runtime/atomic/atomic_andor_generic.go

Documentation: internal/runtime/atomic

     1  // Copyright 2023 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build arm || wasm
     6  
     7  // Export some functions via linkname to assembly in sync/atomic.
     8  //
     9  //go:linkname And32
    10  //go:linkname Or32
    11  //go:linkname And64
    12  //go:linkname Or64
    13  //go:linkname Anduintptr
    14  //go:linkname Oruintptr
    15  
    16  package atomic
    17  
    18  import _ "unsafe" // For linkname
    19  
    20  //go:nosplit
    21  func And32(ptr *uint32, val uint32) uint32 {
    22  	for {
    23  		old := *ptr
    24  		if Cas(ptr, old, old&val) {
    25  			return old
    26  		}
    27  	}
    28  }
    29  
    30  //go:nosplit
    31  func Or32(ptr *uint32, val uint32) uint32 {
    32  	for {
    33  		old := *ptr
    34  		if Cas(ptr, old, old|val) {
    35  			return old
    36  		}
    37  	}
    38  }
    39  
    40  //go:nosplit
    41  func And64(ptr *uint64, val uint64) uint64 {
    42  	for {
    43  		old := *ptr
    44  		if Cas64(ptr, old, old&val) {
    45  			return old
    46  		}
    47  	}
    48  }
    49  
    50  //go:nosplit
    51  func Or64(ptr *uint64, val uint64) uint64 {
    52  	for {
    53  		old := *ptr
    54  		if Cas64(ptr, old, old|val) {
    55  			return old
    56  		}
    57  	}
    58  }
    59  
    60  //go:nosplit
    61  func Anduintptr(ptr *uintptr, val uintptr) uintptr {
    62  	for {
    63  		old := *ptr
    64  		if Casuintptr(ptr, old, old&val) {
    65  			return old
    66  		}
    67  	}
    68  }
    69  
    70  //go:nosplit
    71  func Oruintptr(ptr *uintptr, val uintptr) uintptr {
    72  	for {
    73  		old := *ptr
    74  		if Casuintptr(ptr, old, old|val) {
    75  			return old
    76  		}
    77  	}
    78  }
    79  

View as plain text