Apache HTTPD
proc_mutex.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_general.h"
18#include "apr_lib.h"
19#include "apr_strings.h"
20#include "apr_portable.h"
21#include "apr_arch_proc_mutex.h"
22#include "apr_arch_file_io.h"
23#include <string.h>
24#include <stddef.h>
25
26#define CurrentTid (*_threadid)
27
28static char *fixed_name(const char *fname, apr_pool_t *pool)
29{
30 char *semname;
31
32 if (fname == NULL)
33 semname = NULL;
34 else {
35 /* Semaphores don't live in the file system, fix up the name */
36 while (*fname == '/' || *fname == '\\') {
37 fname++;
38 }
39
40 semname = apr_pstrcat(pool, "/SEM32/", fname, NULL);
41
42 if (semname[8] == ':') {
43 semname[8] = '$';
44 }
45 }
46
47 return semname;
48}
49
50
51
57
59{
60 return NULL;
61}
62
67
69{
70 return "os2sem";
71}
72
73APR_DECLARE(const char *) apr_proc_mutex_defname(void)
74{
75 return "os2sem";
76}
77
78
80 const char *fname,
83{
85 ULONG rc;
86 char *semname;
87
89 return APR_ENOTIMPL;
90 }
91
93 new->pool = pool;
94 new->owner = 0;
95 new->lock_count = 0;
96 *mutex = new;
97
100
101 if (!rc) {
103 }
104
105 return APR_FROM_OS_ERROR(rc);
106}
107
108
109
111 const char *fname,
113{
114 apr_proc_mutex_t *new;
115 ULONG rc;
116 char *semname;
117
119 new->pool = pool;
120 new->owner = 0;
121 new->lock_count = 0;
122
124 rc = DosOpenMutexSem(semname, &(new->hMutex));
125 *mutex = new;
126
127 if (!rc) {
129 }
130
131 return APR_FROM_OS_ERROR(rc);
132}
133
134
135
137{
139
140 if (rc == 0) {
141 mutex->owner = CurrentTid;
142 mutex->lock_count++;
143 }
144
145 return APR_FROM_OS_ERROR(rc);
146}
147
148
149
151{
153
154 if (rc == 0) {
155 mutex->owner = CurrentTid;
156 mutex->lock_count++;
157 }
158
160}
161
162
163
166{
167 ULONG rc;
168
169 if (timeout <= 0) {
171 }
172 else {
174 }
175
176 if (rc == 0) {
177 mutex->owner = CurrentTid;
178 mutex->lock_count++;
179 }
180
182}
183
184
185
187{
188 ULONG rc;
189
190 if (mutex->owner == CurrentTid && mutex->lock_count > 0) {
191 mutex->lock_count--;
192 rc = DosReleaseMutexSem(mutex->hMutex);
193 return APR_FROM_OS_ERROR(rc);
194 }
195
196 return APR_SUCCESS;
197}
198
199
200
202{
203 ULONG rc;
205
206 if (mutex->owner == CurrentTid) {
207 while (mutex->lock_count > 0 && status == APR_SUCCESS) {
209 }
210 }
211
212 if (status != APR_SUCCESS) {
213 return status;
214 }
215
216 if (mutex->hMutex == 0) {
217 return APR_SUCCESS;
218 }
219
220 rc = DosCloseMutexSem(mutex->hMutex);
221
222 if (!rc) {
223 mutex->hMutex = 0;
224 }
225
226 return APR_FROM_OS_ERROR(rc);
227}
228
230
232
233
234
235/* Implement OS-specific accessors defined in apr_portable.h */
236
240{
241 *ospmutex = pmutex->hMutex;
242 if (mech) {
244 }
245 return APR_SUCCESS;
246}
247
250{
252}
253
259{
260 apr_proc_mutex_t *new;
261 if (pool == NULL) {
262 return APR_ENOPOOL;
263 }
265 return APR_ENOTIMPL;
266 }
267
269 new->pool = pool;
270 new->owner = 0;
271 new->lock_count = 0;
272 new->hMutex = *ospmutex;
273 *pmutex = new;
274
275 if (register_cleanup) {
278 }
279 return APR_SUCCESS;
280}
281
285{
287 0, pool);
288}
289
#define FALSE
Definition abts.h:35
APR Miscellaneous library routines.
APR general purpose library routines.
APR Portability Routines.
APR Strings library.
#define APR_ENOTIMPL
Definition apr_errno.h:476
#define APR_TIMEUP
Definition apr_errno.h:450
#define APR_ENOPOOL
Definition apr_errno.h:290
#define APR_EBUSY
Definition apr_errno.h:480
const char apr_lockmech_e mech
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 * fname
#define APR_PERMS_SET_ENOTIMPL(type)
#define APR_POOL_IMPLEMENT_ACCESSOR(type)
Definition apr_pools.h:91
apr_os_proc_mutex_t * ospmutex
apr_os_file_t int register_cleanup
apr_global_mutex_t * pmutex
apr_lockmech_e
@ APR_LOCK_DEFAULT_TIMED
@ APR_LOCK_DEFAULT
int int status
#define apr_time_as_msec(time)
Definition apr_time.h:72
apr_int64_t apr_interval_time_t
Definition apr_time.h:55
return NULL
Definition mod_so.c:359
#define CurrentTid
Definition proc_mutex.c:26
static char * fixed_name(const char *fname, apr_pool_t *pool)
Definition proc_mutex.c:28
static void proc_mutex(abts_case *tc, void *data)
IN ULONG IN INT timeout