]>
git.saurik.com Git - apple/xnu.git/blob - tools/tests/libMicro/pthread_create.c
4 * The contents of this file are subject to the terms
5 * of the Common Development and Distribution License
6 * (the "License"). You may not use this file except
7 * in compliance with the License.
9 * You can obtain a copy of the license at
10 * src/OPENSOLARIS.LICENSE
11 * or http://www.opensolaris.org/os/licensing.
12 * See the License for the specific language governing
13 * permissions and limitations under the License.
15 * When distributing Covered Code, include this CDDL
16 * HEADER in each file and include the License file at
17 * usr/src/OPENSOLARIS.LICENSE. If applicable,
18 * add the following below this CDDL HEADER, with the
19 * fields enclosed by brackets "[]" replaced with your
20 * own identifying information: Portions Copyright [yyyy]
21 * [name of copyright owner]
27 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
28 * Use is subject to license terms.
41 pthread_t
*ts_threads
;
42 pthread_attr_t
*ts_attr
;
43 pthread_mutex_t ts_lock
;
53 lm_tsdsize
= sizeof (tsd_t
);
55 (void) sprintf(lm_usage
,
56 " [-s stacksize] (specify stacksize)\n"
57 "notes: measures pthread_create\n");
59 (void) sprintf(lm_optstr
, "s:");
65 benchmark_optswitch(int opt
, char *optarg
)
69 opts
= sizetoll(optarg
);
79 benchmark_initworker(void *tsd
)
81 tsd_t
*ts
= (tsd_t
*)tsd
;
84 ts
->ts_threads
= calloc(lm_optB
, sizeof (pthread_t
));
85 (void) pthread_mutex_init(&ts
->ts_lock
, NULL
);
88 ts
->ts_attr
= malloc(sizeof (pthread_attr_t
));
89 (void) pthread_attr_init(ts
->ts_attr
);
90 if ((errors
= pthread_attr_setstacksize(ts
->ts_attr
, opts
))
93 perror("pthread_attr_setstacksize");
102 benchmark_initbatch(void *tsd
)
104 tsd_t
*ts
= (tsd_t
*)tsd
;
106 (void) pthread_mutex_lock(&ts
->ts_lock
);
115 tsd_t
*ts
= (tsd_t
*)tsd
;
117 (void) pthread_mutex_lock(&ts
->ts_lock
);
118 (void) pthread_mutex_unlock(&ts
->ts_lock
);
124 benchmark(void *tsd
, result_t
*res
)
127 tsd_t
*ts
= (tsd_t
*)tsd
;
130 for (i
= 0; i
< lm_optB
; i
++) {
131 if ((error
= pthread_create(ts
->ts_threads
+ i
,
132 ts
->ts_attr
, func
, tsd
)) != 0) {
134 perror("pthread_create");
135 ts
->ts_threads
[i
] = 0;
140 res
->re_count
= lm_optB
;
146 benchmark_finibatch(void *tsd
)
148 tsd_t
*ts
= (tsd_t
*)tsd
;
152 (void) pthread_mutex_unlock(&ts
->ts_lock
);
154 for (i
= 0; i
< lm_optB
; i
++)
155 if (ts
->ts_threads
[i
] == 0 ||
156 pthread_join(ts
->ts_threads
[i
], NULL
) < 0) {