Home | History | Annotate | Download | only in runtime
      1 // Copyright 2015 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 //go:noescape
     10 func xadd(ptr *uint32, delta int32) uint32
     11 
     12 //go:noescape
     13 func xadd64(ptr *uint64, delta int64) uint64
     14 
     15 //go:noescape
     16 //go:linkname xadduintptr runtime.xadd64
     17 func xadduintptr(ptr *uintptr, delta uintptr) uintptr
     18 
     19 //go:noescape
     20 func xchg(ptr *uint32, new uint32) uint32
     21 
     22 //go:noescape
     23 func xchg64(ptr *uint64, new uint64) uint64
     24 
     25 // NO go:noescape annotation; see atomic_pointer.go.
     26 func xchgp1(ptr unsafe.Pointer, new unsafe.Pointer) unsafe.Pointer
     27 
     28 //go:noescape
     29 func xchguintptr(ptr *uintptr, new uintptr) uintptr
     30 
     31 //go:noescape
     32 func atomicload(ptr *uint32) uint32
     33 
     34 //go:noescape
     35 func atomicload64(ptr *uint64) uint64
     36 
     37 //go:noescape
     38 func atomicloadp(ptr unsafe.Pointer) unsafe.Pointer
     39 
     40 //go:nosplit
     41 func atomicor8(addr *uint8, v uint8) {
     42 	// TODO(dfc) implement this in asm.
     43 	// Align down to 4 bytes and use 32-bit CAS.
     44 	uaddr := uintptr(unsafe.Pointer(addr))
     45 	addr32 := (*uint32)(unsafe.Pointer(uaddr &^ 3))
     46 	word := uint32(v) << ((uaddr & 3) * 8) // little endian
     47 	for {
     48 		old := *addr32
     49 		if cas(addr32, old, old|word) {
     50 			return
     51 		}
     52 	}
     53 }
     54 
     55 //go:nosplit
     56 func atomicand8(addr *uint8, v uint8) {
     57 	// TODO(dfc) implement this in asm.
     58 	// Align down to 4 bytes and use 32-bit CAS.
     59 	uaddr := uintptr(unsafe.Pointer(addr))
     60 	addr32 := (*uint32)(unsafe.Pointer(uaddr &^ 3))
     61 	word := uint32(v) << ((uaddr & 3) * 8)    // little endian
     62 	mask := uint32(0xFF) << ((uaddr & 3) * 8) // little endian
     63 	word |= ^mask
     64 	for {
     65 		old := *addr32
     66 		if cas(addr32, old, old&word) {
     67 			return
     68 		}
     69 	}
     70 }
     71 
     72 //go:noescape
     73 func cas64(ptr *uint64, old, new uint64) bool
     74 
     75 //go:noescape
     76 func atomicstore(ptr *uint32, val uint32)
     77 
     78 //go:noescape
     79 func atomicstore64(ptr *uint64, val uint64)
     80 
     81 // NO go:noescape annotation; see atomic_pointer.go.
     82 func atomicstorep1(ptr unsafe.Pointer, val unsafe.Pointer)
     83