diff --git a/compiler-rt/test/tsan/Darwin/libcxx-shared-ptr-stress.mm b/compiler-rt/test/tsan/Darwin/libcxx-shared-ptr-stress.mm --- a/compiler-rt/test/tsan/Darwin/libcxx-shared-ptr-stress.mm +++ b/compiler-rt/test/tsan/Darwin/libcxx-shared-ptr-stress.mm @@ -3,33 +3,35 @@ #import -#import +#import +#import +#import #import -#import -_Atomic(long) shared_call_counter = 0; -_Atomic(long) weak_call_counter = 0; -_Atomic(long) destructor_counter = 0; -_Atomic(long) weak_destroyed_counter = 0; +std::atomic shared_call_counter(0); +std::atomic weak_call_counter(0); +std::atomic destructor_counter(0); +std::atomic weak_destroyed_counter(0); struct MyStruct { - _Atomic(long) self_counter = 0; + std::atomic self_counter; + MyStruct() : self_counter(0) { } virtual void shared_call() { - atomic_fetch_add_explicit(&self_counter, 1, memory_order_relaxed); - atomic_fetch_add_explicit(&shared_call_counter, 1, memory_order_relaxed); + std::atomic_fetch_add_explicit(&self_counter, 1, std::memory_order_relaxed); + std::atomic_fetch_add_explicit(&shared_call_counter, 1, std::memory_order_relaxed); } virtual void weak_call() { - atomic_fetch_add_explicit(&weak_call_counter, 1, memory_order_relaxed); + std::atomic_fetch_add_explicit(&weak_call_counter, 1, std::memory_order_relaxed); } virtual ~MyStruct() { long n = self_counter; assert(n == 1000); - atomic_fetch_add_explicit(&destructor_counter, 1, memory_order_relaxed); + std::atomic_fetch_add_explicit(&destructor_counter, 1, std::memory_order_relaxed); } }; int main(int argc, const char *argv[]) { - fprintf(stderr, "Hello world.\n"); + std::fprintf(stderr, "Hello world.\n"); dispatch_queue_t q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); @@ -51,7 +53,7 @@ if (weak_copy) { weak_copy->weak_call(); } else { - atomic_fetch_add_explicit(&weak_destroyed_counter, 1, memory_order_relaxed); + std::atomic_fetch_add_explicit(&weak_destroyed_counter, 1, std::memory_order_relaxed); break; } } @@ -60,12 +62,12 @@ dispatch_group_wait(g, DISPATCH_TIME_FOREVER); - fprintf(stderr, "shared_call_counter = %ld\n", shared_call_counter); - fprintf(stderr, "weak_call_counter = %ld\n", weak_call_counter); - fprintf(stderr, "destructor_counter = %ld\n", destructor_counter); - fprintf(stderr, "weak_destroyed_counter = %ld\n", weak_destroyed_counter); + std::fprintf(stderr, "shared_call_counter = %ld\n", shared_call_counter.load()); + std::fprintf(stderr, "weak_call_counter = %ld\n", weak_call_counter.load()); + std::fprintf(stderr, "destructor_counter = %ld\n", destructor_counter.load()); + std::fprintf(stderr, "weak_destroyed_counter = %ld\n", weak_destroyed_counter.load()); - fprintf(stderr, "Done.\n"); + std::fprintf(stderr, "Done.\n"); } // CHECK: Hello world. diff --git a/compiler-rt/test/tsan/libdispatch/groups-destructor.cpp b/compiler-rt/test/tsan/libdispatch/groups-destructor.cpp --- a/compiler-rt/test/tsan/libdispatch/groups-destructor.cpp +++ b/compiler-rt/test/tsan/libdispatch/groups-destructor.cpp @@ -3,21 +3,21 @@ #include -#include -#include +#include #include +#include -_Atomic(long) destructor_counter = 0; +std::atomic destructor_counter(0); struct MyStruct { virtual ~MyStruct() { usleep(10000); - atomic_fetch_add_explicit(&destructor_counter, 1, memory_order_relaxed); + std::atomic_fetch_add_explicit(&destructor_counter, 1, std::memory_order_relaxed); } }; int main(int argc, const char *argv[]) { - fprintf(stderr, "Hello world.\n"); + std::fprintf(stderr, "Hello world.\n"); dispatch_queue_t q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_group_t g = dispatch_group_create(); @@ -33,10 +33,10 @@ dispatch_group_wait(g, DISPATCH_TIME_FOREVER); if (destructor_counter != 100) { - abort(); + std::abort(); } - fprintf(stderr, "Done.\n"); + std::fprintf(stderr, "Done.\n"); } // CHECK: Hello world.