Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / BlocksRuntime / dispatch_async.c
bloba6f9c1f7500e21c1c08425b4fb2e11cb9c241ec9
1 //
2 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
3 // See https://llvm.org/LICENSE.txt for license information.
4 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 #include <CoreFoundation/CoreFoundation.h>
8 #include <dispatch/dispatch.h>
9 #include <unistd.h>
10 //#import <Foundation/Foundation.h>
11 #include <Block.h>
13 // CONFIG rdar://problem/6371811
15 const char *whoami = "nobody";
17 void EnqueueStuff(dispatch_queue_t q)
19 __block CFIndex counter;
21 // above call has a side effect: it works around:
22 // <rdar://problem/6225809> __block variables not implicitly imported into intermediate scopes
23 dispatch_async(q, ^{
24 counter = 0;
25 });
28 dispatch_async(q, ^{
29 //printf("outer block.\n");
30 counter++;
31 dispatch_async(q, ^{
32 //printf("inner block.\n");
33 counter--;
34 if(counter == 0) {
35 printf("%s: success\n", whoami);
36 exit(0);
38 });
39 if(counter == 0) {
40 printf("already done? inconceivable!\n");
41 exit(1);
43 });
46 int main (int argc, const char * argv[]) {
47 dispatch_queue_t q = dispatch_queue_create("queue", NULL);
49 whoami = argv[0];
51 EnqueueStuff(q);
53 dispatch_main();
54 printf("shouldn't get here\n");
55 return 1;