Index: compiler-rt/trunk/test/tsan/Darwin/gcd-after.mm =================================================================== --- compiler-rt/trunk/test/tsan/Darwin/gcd-after.mm +++ compiler-rt/trunk/test/tsan/Darwin/gcd-after.mm @@ -1,37 +1,38 @@ -// RUN: %clang_tsan %s -o %t -framework Foundation +// RUN: %clang_tsan %s -o %t // RUN: %run %t 2>&1 | FileCheck %s -#import +#include "dispatch/dispatch.h" + +#include long my_global; long my_global2; +dispatch_semaphore_t done; void callback(void *context) { my_global2 = 42; - dispatch_async(dispatch_get_main_queue(), ^{ - CFRunLoopStop(CFRunLoopGetMain()); - }); + dispatch_semaphore_signal(done); } int main(int argc, const char *argv[]) { fprintf(stderr, "start\n"); + done = dispatch_semaphore_create(0); - my_global = 10; dispatch_queue_t q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); + + my_global = 10; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10 * NSEC_PER_MSEC)), q, ^{ my_global = 42; - dispatch_async(dispatch_get_main_queue(), ^{ - CFRunLoopStop(CFRunLoopGetMain()); - }); + dispatch_semaphore_signal(done); }); - CFRunLoopRun(); + dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER); my_global2 = 10; dispatch_after_f(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10 * NSEC_PER_MSEC)), q, NULL, &callback); - CFRunLoopRun(); + dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER); fprintf(stderr, "done\n"); return 0; } Index: compiler-rt/trunk/test/tsan/Darwin/gcd-async-norace.mm =================================================================== --- compiler-rt/trunk/test/tsan/Darwin/gcd-async-norace.mm +++ compiler-rt/trunk/test/tsan/Darwin/gcd-async-norace.mm @@ -1,24 +1,25 @@ -// RUN: %clang_tsan %s -o %t -framework Foundation +// RUN: %clang_tsan %s -o %t // RUN: %run %t 2>&1 | FileCheck %s -#import +#include "dispatch/dispatch.h" + +#include long global; int main() { - NSLog(@"Hello world."); + fprintf(stderr, "Hello world.\n"); + dispatch_semaphore_t done = dispatch_semaphore_create(0); global = 42; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ global = 43; - dispatch_sync(dispatch_get_main_queue(), ^{ - CFRunLoopStop(CFRunLoopGetCurrent()); - }); + dispatch_semaphore_signal(done); }); - CFRunLoopRun(); - NSLog(@"Done."); + dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER); + fprintf(stderr, "Done.\n"); } // CHECK: Hello world. Index: compiler-rt/trunk/test/tsan/Darwin/gcd-async-race.mm =================================================================== --- compiler-rt/trunk/test/tsan/Darwin/gcd-async-race.mm +++ compiler-rt/trunk/test/tsan/Darwin/gcd-async-race.mm @@ -1,15 +1,16 @@ -// RUN: %clang_tsan %s -o %t -framework Foundation +// RUN: %clang_tsan %s -o %t // RUN: %deflake %run %t 2>&1 | FileCheck %s -#import +#include "dispatch/dispatch.h" -#import "../test.h" +#include "../test.h" long global; int main() { - NSLog(@"Hello world."); + fprintf(stderr, "Hello world.\n"); print_address("addr=", 1, &global); + dispatch_semaphore_t done = dispatch_semaphore_create(0); barrier_init(&barrier, 2); global = 42; @@ -22,13 +23,11 @@ barrier_wait(&barrier); global = 44; - dispatch_sync(dispatch_get_main_queue(), ^{ - CFRunLoopStop(CFRunLoopGetCurrent()); - }); + dispatch_semaphore_signal(done); }); - CFRunLoopRun(); - NSLog(@"Done."); + dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER); + fprintf(stderr, "Done.\n"); } // CHECK: Hello world. Index: compiler-rt/trunk/test/tsan/Darwin/gcd-barrier-race.mm =================================================================== --- compiler-rt/trunk/test/tsan/Darwin/gcd-barrier-race.mm +++ compiler-rt/trunk/test/tsan/Darwin/gcd-barrier-race.mm @@ -1,15 +1,16 @@ -// RUN: %clang_tsan %s -o %t -framework Foundation +// RUN: %clang_tsan %s -o %t // RUN: %deflake %run %t 2>&1 | FileCheck %s -#import +#include "dispatch/dispatch.h" -#import "../test.h" +#include "../test.h" long global; int main() { fprintf(stderr, "Hello world.\n"); print_address("addr=", 1, &global); + dispatch_semaphore_t done = dispatch_semaphore_create(0); barrier_init(&barrier, 2); dispatch_queue_t q = dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT); @@ -31,13 +32,11 @@ barrier_wait(&barrier); global = 44; - dispatch_sync(dispatch_get_main_queue(), ^{ - CFRunLoopStop(CFRunLoopGetCurrent()); - }); + dispatch_semaphore_signal(done); }); }); - CFRunLoopRun(); + dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER); fprintf(stderr, "Done.\n"); } Index: compiler-rt/trunk/test/tsan/Darwin/gcd-barrier.mm =================================================================== --- compiler-rt/trunk/test/tsan/Darwin/gcd-barrier.mm +++ compiler-rt/trunk/test/tsan/Darwin/gcd-barrier.mm @@ -1,15 +1,15 @@ -// RUN: %clang_tsan %s -o %t -framework Foundation +// RUN: %clang_tsan %s -o %t // RUN: %run %t 2>&1 | FileCheck %s -#import +#include "dispatch/dispatch.h" -#import "../test.h" +#include "../test.h" long global; int main() { fprintf(stderr, "Hello world.\n"); - print_address("addr=", 1, &global); + dispatch_semaphore_t done = dispatch_semaphore_create(0); barrier_init(&barrier, 2); dispatch_queue_t q = dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT); @@ -34,13 +34,11 @@ }); barrier_wait(&barrier); - - dispatch_sync(dispatch_get_main_queue(), ^{ - CFRunLoopStop(CFRunLoopGetCurrent()); - }); + + dispatch_semaphore_signal(done); }); - CFRunLoopRun(); + dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER); fprintf(stderr, "Done.\n"); } Index: compiler-rt/trunk/test/tsan/Darwin/gcd-blocks.mm =================================================================== --- compiler-rt/trunk/test/tsan/Darwin/gcd-blocks.mm +++ compiler-rt/trunk/test/tsan/Darwin/gcd-blocks.mm @@ -1,29 +1,32 @@ -// RUN: %clangxx_tsan %s -o %t -framework Foundation +// RUN: %clang_tsan %s -o %t // RUN: %run %t 2>&1 | FileCheck %s -#import +#include "dispatch/dispatch.h" + +#include +#include int main() { fprintf(stderr, "start\n"); + dispatch_semaphore_t done = dispatch_semaphore_create(0); dispatch_queue_t background_q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); - dispatch_queue_t main_q = dispatch_get_main_queue(); + dispatch_queue_t serial_q = dispatch_queue_create("my.queue", DISPATCH_QUEUE_SERIAL); + assert(background_q != serial_q); dispatch_async(background_q, ^{ __block long block_var = 0; - dispatch_sync(main_q, ^{ + dispatch_sync(serial_q, ^{ block_var = 42; }); fprintf(stderr, "block_var = %ld\n", block_var); - dispatch_sync(dispatch_get_main_queue(), ^{ - CFRunLoopStop(CFRunLoopGetCurrent()); - }); + dispatch_semaphore_signal(done); }); - - CFRunLoopRun(); + + dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER); fprintf(stderr, "done\n"); }