Apache HTTPD
testlockperf.c
Go to the documentation of this file.
1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "apr_thread_proc.h"
18#include "apr_thread_mutex.h"
19#include "apr_thread_rwlock.h"
20#include "apr_file_io.h"
21#include "apr_errno.h"
22#include "apr_general.h"
23#include "apr_getopt.h"
24#include "errno.h"
25#include <stdio.h>
26#include <stdlib.h>
27#include "testutil.h"
28
29#if !APR_HAS_THREADS
30int main(void)
31{
32 printf("This program won't work on this platform because there is no "
33 "support for threads.\n");
34 return 0;
35}
36#else /* !APR_HAS_THREADS */
37
38#define DEFAULT_MAX_COUNTER 1000000
39#define MAX_THREADS 6
40
41static int verbose = 0;
42static long mutex_counter;
44
47apr_status_t test_thread_mutex(int num_threads); /* apr_thread_mutex_t */
48
51apr_status_t test_thread_rwlock(int num_threads); /* apr_thread_rwlock_t */
52
54
56int i = 0, x = 0;
57
59{
60 int i;
61
62 for (i = 0; i < max_counter; i++) {
63 if (data) {
65 }
66 else {
68 }
71 }
72 return NULL;
73}
74
76{
77 int i;
78
79 for (i = 0; i < max_counter; i++) {
83 }
84 return NULL;
85}
86
88{
92 int i;
93
94 mutex_counter = 0;
95
96 printf("apr_thread_mutex_t Tests\n");
97 printf("%-60s", " Initializing the apr_thread_mutex_t (UNNESTED)");
99 if (s[0] != APR_SUCCESS) {
100 printf("Failed!\n");
101 return s[0];
102 }
103 printf("OK\n");
104
106 /* set_concurrency(4)? -aaron */
107 printf(" Starting %d threads ", num_threads);
108 for (i = 0; i < num_threads; ++i) {
110 if (s[i] != APR_SUCCESS) {
111 printf("Failed!\n");
112 return s[i];
113 }
114 }
115 printf("OK\n");
116
119
120 /* printf("%-60s", " Waiting for threads to exit"); */
121 for (i = 0; i < num_threads; ++i) {
122 apr_thread_join(&s[i], t[i]);
123 }
124 /* printf("OK\n"); */
125
127 printf("microseconds: %" APR_INT64_T_FMT " usec\n",
130 printf("error: counter = %ld\n", mutex_counter);
131
132 return APR_SUCCESS;
133}
134
136{
140 int i;
141
142 mutex_counter = 0;
143
144 printf("apr_thread_mutex_t Tests\n");
145 printf("%-60s", " Initializing the apr_thread_mutex_t (NESTED)");
147 if (s[0] != APR_SUCCESS) {
148 printf("Failed!\n");
149 return s[0];
150 }
151 printf("OK\n");
152
154 /* set_concurrency(4)? -aaron */
155 printf(" Starting %d threads ", num_threads);
156 for (i = 0; i < num_threads; ++i) {
158 if (s[i] != APR_SUCCESS) {
159 printf("Failed!\n");
160 return s[i];
161 }
162 }
163 printf("OK\n");
164
167
168 /* printf("%-60s", " Waiting for threads to exit"); */
169 for (i = 0; i < num_threads; ++i) {
170 apr_thread_join(&s[i], t[i]);
171 }
172 /* printf("OK\n"); */
173
175 printf("microseconds: %" APR_INT64_T_FMT " usec\n",
178 printf("error: counter = %ld\n", mutex_counter);
179
180 return APR_SUCCESS;
181}
182
184{
189 int i;
190
191 mutex_counter = 0;
192
194
195 printf("apr_thread_mutex_t Tests\n");
196 printf("%-60s", " Initializing the apr_thread_mutex_t (TIMED)");
198 if (s[0] != APR_SUCCESS) {
199 printf("Failed!\n");
200 return s[0];
201 }
202 printf("OK\n");
203
205 /* set_concurrency(4)? -aaron */
206 printf(" Starting %d threads ", num_threads);
207 for (i = 0; i < num_threads; ++i) {
209 if (s[i] != APR_SUCCESS) {
210 printf("Failed!\n");
211 return s[i];
212 }
213 }
214 printf("OK\n");
215
218
219 /* printf("%-60s", " Waiting for threads to exit"); */
220 for (i = 0; i < num_threads; ++i) {
221 apr_thread_join(&s[i], t[i]);
222 }
223 /* printf("OK\n"); */
224
226 printf("microseconds: %" APR_INT64_T_FMT " usec\n",
229 printf("error: counter = %ld\n", mutex_counter);
230
231 return APR_SUCCESS;
232}
233
235{
239 int i;
240
241 mutex_counter = 0;
242
243 printf("apr_thread_rwlock_t Tests\n");
244 printf("%-60s", " Initializing the apr_thread_rwlock_t");
246 if (s[0] != APR_SUCCESS) {
247 printf("Failed!\n");
248 return s[0];
249 }
250 printf("OK\n");
251
253 /* set_concurrency(4)? -aaron */
254 printf(" Starting %d threads ", num_threads);
255 for (i = 0; i < num_threads; ++i) {
257 if (s[i] != APR_SUCCESS) {
258 printf("Failed!\n");
259 return s[i];
260 }
261 }
262 printf("OK\n");
263
266
267 /* printf("%-60s", " Waiting for threads to exit"); */
268 for (i = 0; i < num_threads; ++i) {
269 apr_thread_join(&s[i], t[i]);
270 }
271 /* printf("OK\n"); */
272
274 printf("microseconds: %" APR_INT64_T_FMT " usec\n",
277 printf("error: counter = %ld\n", mutex_counter);
278
279 return APR_SUCCESS;
280}
281
282int main(int argc, const char * const *argv)
283{
284 apr_status_t rv;
285 char errmsg[200];
287 char optchar;
288 const char *optarg;
289
290 printf("APR Lock Performance Test\n==============\n\n");
291
294
296 exit(-1);
297
298 if ((rv = apr_getopt_init(&opt, pool, argc, argv)) != APR_SUCCESS) {
299 fprintf(stderr, "Could not set up to parse options: [%d] %s\n",
300 rv, apr_strerror(rv, errmsg, sizeof errmsg));
301 exit(-1);
302 }
303
304 while ((rv = apr_getopt(opt, "c:v", &optchar, &optarg)) == APR_SUCCESS) {
305 if (optchar == 'c') {
307 }
308 else if (optchar == 'v') {
309 verbose = 1;
310 }
311 }
312
313 if (rv != APR_SUCCESS && rv != APR_EOF) {
314 fprintf(stderr, "Could not parse options: [%d] %s\n",
315 rv, apr_strerror(rv, errmsg, sizeof errmsg));
316 exit(-1);
317 }
318
319 for (i = 1; i <= MAX_THREADS; ++i) {
320 if ((rv = test_thread_mutex(i)) != APR_SUCCESS) {
321 fprintf(stderr,"thread_mutex test failed : [%d] %s\n",
322 rv, apr_strerror(rv, (char*)errmsg, 200));
323 exit(-3);
324 }
325
326 if ((rv = test_thread_mutex_nested(i)) != APR_SUCCESS) {
327 fprintf(stderr,"thread_mutex (NESTED) test failed : [%d] %s\n",
328 rv, apr_strerror(rv, (char*)errmsg, 200));
329 exit(-4);
330 }
331
332 if ((rv = test_thread_mutex_timed(i)) != APR_SUCCESS) {
333 fprintf(stderr,"thread_mutex (TIMED) test failed : [%d] %s\n",
334 rv, apr_strerror(rv, (char*)errmsg, 200));
335 exit(-5);
336 }
337
338 if ((rv = test_thread_rwlock(i)) != APR_SUCCESS) {
339 fprintf(stderr,"thread_rwlock test failed : [%d] %s\n",
340 rv, apr_strerror(rv, (char*)errmsg, 200));
341 exit(-6);
342 }
343 }
344
345 return 0;
346}
347
348#endif /* !APR_HAS_THREADS */
static int verbose
Definition abts.c:24
APR Error Codes.
APR File I/O Handling.
APR Miscellaneous library routines.
APR Command Arguments (getopt)
APR Thread Mutex Routines.
APR Thread and Process Library.
APR Reader/Writer Lock Routines.
#define APR_EOF
Definition apr_errno.h:461
apr_size_t size
const char int apr_pool_t * pool
Definition apr_cstr.h:84
#define APR_SUCCESS
Definition apr_errno.h:225
int apr_status_t
Definition apr_errno.h:44
void * data
apr_pool_t int argc
Definition apr_getopt.h:104
apr_int32_t opt
apr_interval_time_t t
#define apr_pool_create(newpool, parent)
Definition apr_pools.h:322
const char * s
Definition apr_strings.h:95
apr_int64_t apr_interval_time_t
Definition apr_time.h:55
apr_int64_t apr_time_t
Definition apr_time.h:45
#define apr_time_from_sec(sec)
Definition apr_time.h:78
const char * argv[3]
return NULL
Definition mod_so.c:359
int i
Definition mod_so.c:347
apr_status_t apr_thread_join(apr_status_t *retval, apr_thread_t *thd)
Definition thread.c:166
apr_status_t apr_thread_create(apr_thread_t **new, apr_threadattr_t *attr, apr_thread_start_t func, void *data, apr_pool_t *pool)
Definition thread.c:73
int main(void)
IN ULONG IN INT timeout