]>
git.saurik.com Git - apple/xnu.git/blob - tools/tests/libMicro/mutex.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.
48 pthread_mutex_t
*lock
;
52 pthread_mutex_t
*ts_lock
;
58 lm_tsdsize
= sizeof (tsd_t
);
60 (void) sprintf(lm_usage
,
61 " [-t] (create dummy thread so we are multithreaded)\n"
62 " [-p] (use inter-process mutex (not support everywhere))\n"
63 " [-h usecs] (specify mutex hold time (default 0)\n"
64 "notes: measures uncontended pthread_mutex_[un,]lock\n");
66 (void) sprintf(lm_optstr
, "tph:o:");
68 (void) sprintf(lm_header
, "%8s", "holdtime");
75 benchmark_optswitch(int opt
, char *optarg
)
87 opth
= sizetoint(optarg
);
91 opto
= sizetoint(optarg
);
110 pthread_mutexattr_t attr
;
114 lock
= (pthread_mutex_t
*)mmap(NULL
,
116 PROT_READ
| PROT_WRITE
,
117 optp
?(MAP_ANON
| MAP_SHARED
):MAP_ANON
|MAP_PRIVATE
,
120 if (lock
== MAP_FAILED
) {
123 (void) pthread_mutexattr_init(&attr
);
125 (void) pthread_mutexattr_setpshared(&attr
,
126 PTHREAD_PROCESS_SHARED
);
128 if (pthread_mutex_init(lock
, &attr
) != 0)
136 benchmark_initworker(void *tsd
)
139 tsd_t
*ts
= (tsd_t
*)tsd
;
147 if (pthread_create(&tid
, NULL
, dummy
, NULL
) != 0) {
160 long long s
= getusecs();
162 while (getusecs() - s
< usecs
)
167 benchmark(void *tsd
, result_t
*res
)
169 tsd_t
*ts
= (tsd_t
*)tsd
;
172 for (i
= 0; i
< lm_optB
; i
++) {
174 (void) pthread_mutex_lock(ts
->ts_lock
);
177 (void) pthread_mutex_unlock(ts
->ts_lock
);
181 res
->re_count
= lm_optB
;
189 static char result
[256];
191 (void) sprintf(result
, "%8d", opth
);