]>
git.saurik.com Git - apple/libdispatch.git/blob - testing/dispatch_pingpong.c
1 #include <dispatch/dispatch.h>
4 #include "dispatch_test.h"
7 const uint32_t final
= 1000000; // 10M
9 void pingpongloop(dispatch_group_t group
, dispatch_queue_t ping
, dispatch_queue_t pong
, size_t counter
) {
10 //printf("[%p] %s: %lu\n", (void*)(uintptr_t)pthread_self(), dispatch_queue_get_label(dispatch_get_current_queue()), counter);
11 if (counter
< final
) {
12 dispatch_group_async(group
, pong
, ^{ pingpongloop(group
, pong
, ping
, counter
+1); });
20 test_start("Dispatch Ping Pong");
22 dispatch_queue_t ping
= dispatch_queue_create("ping", NULL
);
23 test_ptr_notnull("dispatch_queue_create(ping)", ping
);
24 dispatch_queue_t pong
= dispatch_queue_create("pong", NULL
);
25 test_ptr_notnull("dispatch_queue_create(pong)", pong
);
27 dispatch_group_t group
= dispatch_group_create();
28 test_ptr_notnull("dispatch_group_create", group
);
30 pingpongloop(group
, ping
, pong
, 0);
31 dispatch_group_wait(group
, DISPATCH_TIME_FOREVER
);
33 test_long("count", count
, final
);