github.com/reiver/go@v0.0.0-20150109200633-1d0c7792f172/src/runtime/atomic_386.go (about)

     1  // Copyright 2009 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  package runtime
     6  
     7  import "unsafe"
     8  
     9  // The calls to nop are to keep these functions from being inlined.
    10  // If they are inlined we have no guarantee that later rewrites of the
    11  // code by optimizers will preserve the relative order of memory accesses.
    12  
    13  //go:nosplit
    14  func atomicload(ptr *uint32) uint32 {
    15  	nop()
    16  	return *ptr
    17  }
    18  
    19  //go:nosplit
    20  func atomicloadp(ptr unsafe.Pointer) unsafe.Pointer {
    21  	nop()
    22  	return *(*unsafe.Pointer)(ptr)
    23  }
    24  
    25  //go:nosplit
    26  func xadd64(ptr *uint64, delta int64) uint64 {
    27  	for {
    28  		old := *ptr
    29  		if cas64(ptr, old, old+uint64(delta)) {
    30  			return old + uint64(delta)
    31  		}
    32  	}
    33  }
    34  
    35  //go:nosplit
    36  func xchg64(ptr *uint64, new uint64) uint64 {
    37  	for {
    38  		old := *ptr
    39  		if cas64(ptr, old, new) {
    40  			return old
    41  		}
    42  	}
    43  }
    44  
    45  //go:noescape
    46  func xadd(ptr *uint32, delta int32) uint32
    47  
    48  //go:noescape
    49  func xchg(ptr *uint32, new uint32) uint32
    50  
    51  // NO go:noescape annotation; see atomic_pointer.go.
    52  func xchgp1(ptr unsafe.Pointer, new unsafe.Pointer) unsafe.Pointer
    53  
    54  //go:noescape
    55  func xchguintptr(ptr *uintptr, new uintptr) uintptr
    56  
    57  //go:noescape
    58  func atomicload64(ptr *uint64) uint64
    59  
    60  //go:noescape
    61  func atomicor8(ptr *uint8, val uint8)
    62  
    63  //go:noescape
    64  func cas64(ptr *uint64, old, new uint64) bool
    65  
    66  //go:noescape
    67  func atomicstore(ptr *uint32, val uint32)
    68  
    69  //go:noescape
    70  func atomicstore64(ptr *uint64, val uint64)
    71  
    72  // NO go:noescape annotation; see atomic_pointer.go.
    73  func atomicstorep1(ptr unsafe.Pointer, val unsafe.Pointer)