mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-04 19:17:47 +00:00
compiler: define atomic intrinsic functions directly
This changes the compiler from treating calls to sync/atomic.* functions as special calls (emitted directly at the call site) to actually defining their declarations when there is no Go SSA implementation. And rely on the inliner to inline these very small functions. This works a bit better in practice. For example, this makes it possible to use these functions in deferred function calls. This commit is a bit large because it also needs to refactor a few things to make it possible to define such intrinsic functions.
This commit is contained in:
committed by
Ron Evans
parent
6dff85c756
commit
e1052f921c
Vendored
+11
@@ -81,6 +81,9 @@ func main() {
|
||||
// test atomic.Value load/store operations
|
||||
testValue(int(3), int(-2))
|
||||
testValue("", "foobar", "baz")
|
||||
|
||||
// Test atomic operations as deferred values.
|
||||
testDefer()
|
||||
}
|
||||
|
||||
func testValue(values ...interface{}) {
|
||||
@@ -93,3 +96,11 @@ func testValue(values ...interface{}) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testDefer() {
|
||||
n1 := int32(5)
|
||||
defer func() {
|
||||
println("deferred atomic add:", n1)
|
||||
}()
|
||||
defer atomic.AddInt32(&n1, 3)
|
||||
}
|
||||
|
||||
Vendored
+1
@@ -33,3 +33,4 @@ StoreUint32: 20
|
||||
StoreUint64: 20
|
||||
StoreUintptr: 20
|
||||
StorePointer: true
|
||||
deferred atomic add: 8
|
||||
|
||||
Reference in New Issue
Block a user