]> Cypherpunks repositories - gostls13.git/commitdiff
misc/cgo/test: use __atomic intrinsics instead of __sync
authorIan Lance Taylor <iant@golang.org>
Thu, 5 Sep 2019 21:35:28 +0000 (14:35 -0700)
committerIan Lance Taylor <iant@golang.org>
Fri, 6 Sep 2019 17:38:58 +0000 (17:38 +0000)
GCC has supported the __atomic intrinsics since 4.7, and clang
supports them as well. 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.

Change-Id: I5e0036ea3300f65c28b1c3d1f3b93fb61c1cd646
Reviewed-on: https://go-review.googlesource.com/c/go/+/193603
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
misc/cgo/test/testx.go

index 27c70403073c29df93da35b63d1259f8edaaf103..67def903aba544cc1b8439c80f8c34b8f2613ba4 100644 (file)
@@ -83,33 +83,18 @@ extern void f7665(void);
 
 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
 }
 
 // issue 8331 part 2 - part 1 in test.go
@@ -496,9 +481,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()