1
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
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.
17
#include "apr_thread_proc.h"
18
#include "apr_errno.h"
19
#include "apr_general.h"
26
static apr_thread_mutex_t *thread_lock;
27
static apr_thread_once_t *control = NULL;
31
static apr_thread_t *t1;
32
static apr_thread_t *t2;
33
static apr_thread_t *t3;
34
static apr_thread_t *t4;
36
/* just some made up number to check on later */
37
static apr_status_t exit_ret_val = 123;
39
static void init_func(void)
44
static void * APR_THREAD_FUNC thread_func1(apr_thread_t *thd, void *data)
48
apr_thread_once(control, init_func);
50
for (i = 0; i < 10000; i++) {
51
apr_thread_mutex_lock(thread_lock);
53
apr_thread_mutex_unlock(thread_lock);
55
apr_thread_exit(thd, exit_ret_val);
59
static void thread_init(abts_case *tc, void *data)
63
rv = apr_thread_once_init(&control, p);
64
ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
66
rv = apr_thread_mutex_create(&thread_lock, APR_THREAD_MUTEX_DEFAULT, p);
67
ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
70
static void create_threads(abts_case *tc, void *data)
74
rv = apr_thread_create(&t1, NULL, thread_func1, NULL, p);
75
ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
76
rv = apr_thread_create(&t2, NULL, thread_func1, NULL, p);
77
ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
78
rv = apr_thread_create(&t3, NULL, thread_func1, NULL, p);
79
ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
80
rv = apr_thread_create(&t4, NULL, thread_func1, NULL, p);
81
ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
84
static void join_threads(abts_case *tc, void *data)
88
apr_thread_join(&s, t1);
89
ABTS_INT_EQUAL(tc, exit_ret_val, s);
90
apr_thread_join(&s, t2);
91
ABTS_INT_EQUAL(tc, exit_ret_val, s);
92
apr_thread_join(&s, t3);
93
ABTS_INT_EQUAL(tc, exit_ret_val, s);
94
apr_thread_join(&s, t4);
95
ABTS_INT_EQUAL(tc, exit_ret_val, s);
98
static void check_locks(abts_case *tc, void *data)
100
ABTS_INT_EQUAL(tc, 40000, x);
103
static void check_thread_once(abts_case *tc, void *data)
105
ABTS_INT_EQUAL(tc, 1, value);
110
static void threads_not_impl(abts_case *tc, void *data)
112
ABTS_NOT_IMPL(tc, "Threads not implemented on this platform");
117
abts_suite *testthread(abts_suite *suite)
119
suite = ADD_SUITE(suite)
122
abts_run_test(suite, threads_not_impl, NULL);
124
abts_run_test(suite, thread_init, NULL);
125
abts_run_test(suite, create_threads, NULL);
126
abts_run_test(suite, join_threads, NULL);
127
abts_run_test(suite, check_locks, NULL);
128
abts_run_test(suite, check_thread_once, NULL);