2 * Copyright (c) 2008-2009 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@
21 #include "config/config.h"
24 #include <dispatch/dispatch.h>
28 #include "dispatch_test.h"
33 dispatch_queue_t queues[QUEUES];
42 size_t iterations = QUEUES * BLOCKS * 0.25;
46 size_t counts[QUEUES] = {};
50 for (q = 0; q < QUEUES; ++q) {
52 for (i = 0; i < BLOCKS; ++i) {
53 if (indices[i].index == q) {
59 for (q = 0; q < QUEUES; ++q) {
60 if (counts[q] > maxcount) {
65 printf("maxcount = %ld\n", maxcount);
68 for (y = 20; y > 0; --y) {
69 for (x = 0; x < QUEUES; ++x) {
70 double fraction = (double)counts[x] / (double)maxcount;
71 double value = fraction * (double)20;
72 printf("%s", (value > y) ? "*" : " ");
79 cascade(void* context) {
80 size_t idx, *idxptr = context;
88 dispatch_async_f(queues[idx], context, cascade);
91 if (__sync_sub_and_fetch(&iterations, 1) == 0) {
100 main(int argc __attribute__((unused)), char* argv[] __attribute__((unused))) {
103 test_start("Dispatch Cascade");
105 for (i = 0; i < QUEUES; ++i) {
106 queues[i] = dispatch_queue_create(NULL, NULL);
109 for (i = 0; i < BLOCKS; ++i) {
110 cascade(&indices[i].index);