Apache HTTPD
thread.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#define INCL_DOSERRORS
18#define INCL_DOS
19#include "apr_arch_threadproc.h"
20#include "apr_thread_proc.h"
21#include "apr_general.h"
22#include "apr_lib.h"
23#include "apr_portable.h"
24#include "apr_arch_file_io.h"
25#include <stdlib.h>
26
28{
30
31 if ((*new) == NULL) {
32 return APR_ENOMEM;
33 }
34
35 (*new)->pool = pool;
36 (*new)->attr = 0;
37 (*new)->stacksize = 0;
38 return APR_SUCCESS;
39}
40
41
42
44{
46 return APR_SUCCESS;
47}
48
49
50
52{
54}
55
57 apr_size_t stacksize)
58{
59 attr->stacksize = stacksize;
60 return APR_SUCCESS;
61}
62
65{
66 return APR_ENOTIMPL;
67}
68
69static void apr_thread_begin(void *arg)
70{
71 apr_thread_t *thread = (apr_thread_t *)arg;
72 thread->exitval = thread->func(thread, thread->data);
73}
74
75
76
80{
82 apr_thread_t *thread;
83
84 thread = (apr_thread_t *)apr_palloc(pool, sizeof(apr_thread_t));
85 *new = thread;
86
87 if (thread == NULL) {
88 return APR_ENOMEM;
89 }
90
91 thread->attr = attr;
92 thread->func = func;
93 thread->data = data;
94 stat = apr_pool_create(&thread->pool, pool);
95
96 if (stat != APR_SUCCESS) {
97 return stat;
98 }
99
100 if (attr == NULL) {
101 stat = apr_threadattr_create(&thread->attr, thread->pool);
102
103 if (stat != APR_SUCCESS) {
104 return stat;
105 }
106 }
107
109 thread->attr->stacksize > 0 ?
111 thread);
112
113 if (thread->tid < 0) {
114 return errno;
115 }
116
117 return APR_SUCCESS;
118}
119
120
121
123{
124 PIB *ppib;
125 TIB *ptib;
127 return ptib->tib_ptib2->tib2_ultid;
128}
129
130
131
133{
134 thd->exitval = retval;
135 _endthread();
136 return -1; /* If we get here something's wrong */
137}
138
139
140
142{
143 ULONG rc;
144 TID waittid = thd->tid;
145
146 if (thd->attr->attr & APR_THREADATTR_DETACHED)
147 return APR_EINVAL;
148
150
152 rc = 0; /* Thread had already terminated */
153
154 *retval = thd->exitval;
155 return APR_OS2_STATUS(rc);
156}
157
158
159
161{
162 thd->attr->attr |= APR_THREADATTR_DETACHED;
163 return APR_SUCCESS;
164}
165
166
167
169{
170 DosSleep(0);
171}
172
173
174
176{
177 *thethd = &thd->tid;
178 return APR_SUCCESS;
179}
180
181
182
185{
186 if ((*thd) == NULL) {
187 (*thd) = (apr_thread_t *)apr_pcalloc(pool, sizeof(apr_thread_t));
188 (*thd)->pool = pool;
189 }
190 (*thd)->tid = *thethd;
191 return APR_SUCCESS;
192}
193
194
195
200
201
202
204{
205 return apr_pool_userdata_get(data, key, thread->pool);
206}
207
208
209
211 apr_status_t (*cleanup) (void *),
212 apr_thread_t *thread)
213{
214 return apr_pool_userdata_set(data, key, cleanup, thread->pool);
215}
216
218
219
220
222{
224
225 if (control->sem) {
226 DosCloseEventSem(control->sem);
227 }
228
229 return APR_SUCCESS;
230}
231
232
233
235 apr_pool_t *p)
236{
237 ULONG rc;
238 *control = (apr_thread_once_t *)apr_pcalloc(p, sizeof(apr_thread_once_t));
239 rc = DosCreateEventSem(NULL, &(*control)->sem, 0, TRUE);
241 return APR_FROM_OS_ERROR(rc);
242}
243
244
245
247 void (*func)(void))
248{
249 if (!control->hit) {
250 ULONG count, rc;
251 rc = DosResetEventSem(control->sem, &count);
252
253 if (rc == 0 && count) {
254 control->hit = 1;
255 func();
256 }
257 }
258
259 return APR_SUCCESS;
260}
#define TRUE
Definition abts.h:38
#define _beginthread(fn, d, pv)
APR Miscellaneous library routines.
APR general purpose library routines.
APR Portability Routines.
APR Thread and Process Library.
void apr_thread_yield()
Definition thread.c:161
static apr_status_t thread_once_cleanup(void *vcontrol)
Definition thread.c:197
int apr_os_thread_equal(apr_os_thread_t tid1, apr_os_thread_t tid2)
Definition thread.c:117
void const char * arg
Definition http_vhost.h:63
#define APR_ENOMEM
Definition apr_errno.h:683
#define APR_NOTDETACH
Definition apr_errno.h:444
#define APR_ENOTIMPL
Definition apr_errno.h:476
#define APR_DETACH
Definition apr_errno.h:442
#define APR_EINVAL
Definition apr_errno.h:711
unsigned int count
Definition apr_md5.h:152
apr_redis_t * rc
Definition apr_redis.h:173
const void apr_status_t(*) apr_status_t(* APR_DECLARE)(void) apr_pool_pre_cleanup_register(apr_pool_t *p
Definition apr_pools.h:646
apr_size_t size
const char int apr_pool_t * pool
Definition apr_cstr.h:84
#define APR_FROM_OS_ERROR(e)
Definition apr_errno.h:1214
#define APR_SUCCESS
Definition apr_errno.h:225
int apr_status_t
Definition apr_errno.h:44
const char * key
void * data
void const char apr_status_t(* cleanup)(void *))
apr_int32_t apr_int32_t on
apr_interval_time_t apr_pollcb_cb_t func
Definition apr_poll.h:422
#define APR_POOL_IMPLEMENT_ACCESSOR(type)
Definition apr_pools.h:91
#define apr_pool_create(newpool, parent)
Definition apr_pools.h:322
#define apr_pcalloc(p, size)
Definition apr_pools.h:465
void *(APR_THREAD_FUNC * apr_thread_start_t)(apr_thread_t *, void *)
const char const char *const const char *const apr_procattr_t * attr
apr_pool_t * p
Definition md_event.c:32
return NULL
Definition mod_so.c:359
apr_status_t apr_thread_exit(apr_thread_t *thd, apr_status_t retval)
Definition thread.c:157
apr_os_thread_t apr_os_thread_current()
Definition thread.c:142
apr_status_t apr_thread_join(apr_status_t *retval, apr_thread_t *thd)
Definition thread.c:166
apr_status_t apr_threadattr_detach_set(apr_threadattr_t *attr, apr_int32_t on)
Definition thread.c:41
apr_status_t apr_thread_data_set(void *data, const char *key, apr_status_t(*cleanup)(void *), apr_thread_t *thread)
Definition thread.c:198
apr_status_t apr_thread_data_get(void **data, const char *key, apr_thread_t *thread)
Definition thread.c:186
apr_status_t apr_threadattr_create(apr_threadattr_t **new, apr_pool_t *pool)
Definition thread.c:24
apr_status_t apr_thread_detach(apr_thread_t *thd)
Definition thread.c:181
apr_status_t apr_threadattr_detach_get(apr_threadattr_t *attr)
Definition thread.c:47
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
#define APR_THREAD_STACKSIZE
#define APR_THREADATTR_DETACHED
static void apr_thread_begin(void *arg)
Definition thread.c:69
apr_status_t exitval
unsigned long tid
struct apr_threadattr_t * attr
apr_pool_t * pool
apr_thread_start_t func