github.com/q45/go@v0.0.0-20151101211701-a4fb8c13db3f/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:noescape
    36  //go:linkname xadduintptr runtime.xadd
    37  func xadduintptr(ptr *uintptr, delta uintptr) uintptr
    38  
    39  //go:nosplit
    40  func xchg64(ptr *uint64, new uint64) uint64 {
    41  	for {
    42  		old := *ptr
    43  		if cas64(ptr, old, new) {
    44  			return old
    45  		}
    46  	}
    47  }
    48  
    49  //go:noescape
    50  func xadd(ptr *uint32, delta int32) uint32
    51  
    52  //go:noescape
    53  func xchg(ptr *uint32, new uint32) uint32
    54  
    55  //go:noescape
    56  func xchguintptr(ptr *uintptr, new uintptr) uintptr
    57  
    58  //go:noescape
    59  func atomicload64(ptr *uint64) uint64
    60  
    61  //go:noescape
    62  func atomicand8(ptr *uint8, val uint8)
    63  
    64  //go:noescape
    65  func atomicor8(ptr *uint8, val uint8)
    66  
    67  // NOTE: Do not add atomicxor8 (XOR is not idempotent).
    68  
    69  //go:noescape
    70  func cas64(ptr *uint64, old, new uint64) bool
    71  
    72  //go:noescape
    73  func atomicstore(ptr *uint32, val uint32)
    74  
    75  //go:noescape
    76  func atomicstore64(ptr *uint64, val uint64)
    77  
    78  // NO go:noescape annotation; see atomic_pointer.go.
    79  func atomicstorep1(ptr unsafe.Pointer, val unsafe.Pointer)