diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2019-02-01 21:55:38 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2019-02-01 21:55:38 +0000 |
commit | b52a3881f04799d410f7ec70d022179c8d734459 (patch) | |
tree | eace57a9fb5df73173371815f0a0e1a5913a77a8 /libgo/misc/cgo | |
parent | a53a893b4fe04ec966a4ec178ee8f394426a5dad (diff) |
runtime, sync: use __atomic intrinsics instead of __sync
GCC has supported the __atomic intrinsics since 4.7. They are better
than the __sync intrinsics in that they specify a memory model and,
more importantly for our purposes, they are reliably implemented
either in the compiler or in libatomic.
Fixes https://gcc.gnu.org/PR52084
Reviewed-on: https://go-review.googlesource.com/c/160820
From-SVN: r268458
Diffstat (limited to 'libgo/misc/cgo')
-rw-r--r-- | libgo/misc/cgo/test/issue7978.go | 28 |
1 files changed, 5 insertions, 23 deletions
diff --git a/libgo/misc/cgo/test/issue7978.go b/libgo/misc/cgo/test/issue7978.go index b057e3eacb2..f0809d35d80 100644 --- a/libgo/misc/cgo/test/issue7978.go +++ b/libgo/misc/cgo/test/issue7978.go @@ -12,33 +12,18 @@ package cgotest void issue7978cb(void); -#if defined(__APPLE__) && defined(__arm__) -// on Darwin/ARM, libSystem doesn't provide implementation of the __sync_fetch_and_add -// primitive, and although gcc supports it, it doesn't inline its definition. -// Clang could inline its definition, so we require clang on Darwin/ARM. -#if defined(__clang__) -#define HAS_SYNC_FETCH_AND_ADD 1 -#else -#define HAS_SYNC_FETCH_AND_ADD 0 -#endif -#else -#define HAS_SYNC_FETCH_AND_ADD 1 -#endif - // use ugly atomic variable sync since that doesn't require calling back into // Go code or OS dependencies static void issue7978c(uint32_t *sync) { -#if HAS_SYNC_FETCH_AND_ADD - while(__sync_fetch_and_add(sync, 0) != 0) + while(__atomic_load_n(sync, __ATOMIC_SEQ_CST) != 0) ; - __sync_fetch_and_add(sync, 1); - while(__sync_fetch_and_add(sync, 0) != 2) + __atomic_add_fetch(sync, 1, __ATOMIC_SEQ_CST); + while(__atomic_load_n(sync, __ATOMIC_SEQ_CST) != 2) ; issue7978cb(); - __sync_fetch_and_add(sync, 1); - while(__sync_fetch_and_add(sync, 0) != 6) + __atomic_add_fetch(sync, 1, __ATOMIC_SEQ_CST); + while(__atomic_load_n(sync, __ATOMIC_SEQ_CST) != 6) ; -#endif } */ import "C" @@ -111,9 +96,6 @@ func test7978(t *testing.T) { if runtime.Compiler == "gccgo" { t.Skip("gccgo can not do stack traces of C code") } - if C.HAS_SYNC_FETCH_AND_ADD == 0 { - t.Skip("clang required for __sync_fetch_and_add support on darwin/arm") - } debug.SetTraceback("2") issue7978sync = 0 go issue7978go() |