]> git.saurik.com Git - apple/libdispatch.git/blob - testing/test.c
libdispatch-84.5.5.tar.gz
[apple/libdispatch.git] / testing / test.c
1 #include <mach/mach.h>
2 #include <mach/mach_time.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <assert.h>
6 #include <pthread.h>
7 #include <dispatch.h>
8
9 int
10 main(void)
11 {
12 void (^wb)(dispatch_item_t) = ^(dispatch_item_t di) {
13 printf("%p\t%p\t%s:\t%llu\n", pthread_self(), di, __func__, mach_absolute_time());
14 };
15 void (^cb)(dispatch_item_t) = ^(dispatch_item_t di) {
16 printf("%p\t%p\t%s:\t%llu\n", pthread_self(), di, __func__, mach_absolute_time());
17 };
18 dispatch_queue_t q;
19 dispatch_item_t di_r;
20 size_t i;
21 bool r;
22
23 q = dispatch_queue_new("test", 0, NULL, NULL, NULL);
24 assert(q != NULL);
25
26 for (i = 0; i < 1000; i++) {
27 r = dispatch_call_wait(q, wb, NULL);
28 assert(r);
29 }
30
31 printf("done with dispatch_call_wait()\n");
32
33 r = dispatch_apply_wait(wb, 10, NULL);
34 assert(r);
35
36 r = dispatch_call(q, wb, cb, NULL, &di_r);
37 assert(r);
38 assert(di_r);
39
40 printf("waiting for dispatch_call() callback\n");
41
42 dispatch_main();
43
44 return 0;
45 }