2 * Copyright (c) 2008-2011 Apple Inc. All rights reserved.
4 * @APPLE_APACHE_LICENSE_HEADER_START@
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * @APPLE_APACHE_LICENSE_HEADER_END@
22 #include <dispatch/dispatch.h>
27 #include "dispatch_test.h"
32 dispatch_queue_t queues[QUEUES];
40 size_t iterations = QUEUES * BLOCKS * 0.25;
43 noop(void *ctxt __attribute__((unused)))
49 cleanup(void *ctxt __attribute__((unused)))
52 for (q = 0; q < QUEUES; ++q) {
53 dispatch_sync_f(queues[q], NULL, noop);
54 dispatch_release(queues[q]);
63 size_t counts[QUEUES] = {};
67 for (q = 0; q < QUEUES; ++q) {
69 for (i = 0; i < BLOCKS; ++i) {
70 if (indices[i].index == q) {
76 for (q = 0; q < QUEUES; ++q) {
77 if (counts[q] > maxcount) {
82 printf("maxcount = %ld\n", maxcount);
85 for (y = 20; y > 0; --y) {
86 for (x = 0; x < QUEUES; ++x) {
87 double fraction = (double)counts[x] / (double)maxcount;
88 double value = fraction * (double)20;
89 printf("%s", (value > y) ? "*" : " ");
96 cascade(void* context)
98 size_t idx, *idxptr = context;
106 dispatch_async_f(queues[idx], context, cascade);
109 if (__sync_sub_and_fetch(&iterations, 1) == 0) {
112 dispatch_async_f(dispatch_get_main_queue(), NULL, cleanup);
117 main(int argc __attribute__((unused)), char* argv[] __attribute__((unused)))
121 dispatch_test_start("Dispatch Cascade");
123 for (i = 0; i < QUEUES; ++i) {
124 queues[i] = dispatch_queue_create(NULL, NULL);
127 for (i = 0; i < BLOCKS; ++i) {
128 cascade(&indices[i].index);