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/*Read/Write locking implementation based on the MultiLock code from
18 * Stephen Beaulieu <[email protected]>
19 */
20
21#include "apr_arch_proc_mutex.h"
22#include "apr_strings.h"
23#include "apr_portable.h"
24
26{
28 if (lock->LockCount != 0) {
29 /* we're still locked... */
30 while (atomic_add(&lock->LockCount , -1) > 1){
31 /* OK we had more than one person waiting on the lock so
32 * the sem is also locked. Release it until we have no more
33 * locks left.
34 */
35 release_sem (lock->Lock);
36 }
37 }
38 delete_sem(lock->Lock);
39 return APR_SUCCESS;
40}
41
43 const char *fname,
46{
49
51 return APR_ENOTIMPL;
52 }
53
55 if (new == NULL){
56 return APR_ENOMEM;
57 }
58
59 if ((stat = create_sem(0, "APR_Lock")) < B_NO_ERROR) {
61 return stat;
62 }
63 new->LockCount = 0;
64 new->Lock = stat;
65 new->pool = pool;
66
69
70 (*mutex) = new;
71 return APR_SUCCESS;
72}
73
75 const char *fname,
77{
78 return APR_SUCCESS;
79}
80
82{
83 int32 stat;
84
85 if (atomic_add(&mutex->LockCount, 1) > 0) {
86 if ((stat = acquire_sem(mutex->Lock)) < B_NO_ERROR) {
87 atomic_add(&mutex->LockCount, -1);
88 return stat;
89 }
90 }
91 return APR_SUCCESS;
92}
93
95{
96 int32 stat;
97
98 if (atomic_add(&mutex->LockCount, 1) > 0) {
99 stat = acquire_sem_etc(mutex->Lock, 1, 0, 0);
100 if (stat < B_NO_ERROR) {
101 atomic_add(&mutex->LockCount, -1);
102 if (stat == B_WOULD_BLOCK) {
103 stat = APR_EBUSY;
104 }
105 return stat;
106 }
107 }
108 return APR_SUCCESS;
109}
110
113{
114 int32 stat;
115
116 if (atomic_add(&mutex->LockCount, 1) > 0) {
117 if (timeout <= 0) {
119 }
120 else {
122 timeout);
123 }
124 if (stat < B_NO_ERROR) {
125 atomic_add(&mutex->LockCount, -1);
126 if (stat == B_TIMED_OUT) {
128 }
129 return stat;
130 }
131 }
132 return APR_SUCCESS;
133}
134
136{
137 int32 stat;
138
139 if (atomic_add(&mutex->LockCount, -1) > 1) {
140 if ((stat = release_sem(mutex->Lock)) < B_NO_ERROR) {
141 atomic_add(&mutex->LockCount, 1);
142 return stat;
143 }
144 }
145 return APR_SUCCESS;
146}
147
149{
151 if ((stat = _proc_mutex_cleanup(mutex)) == APR_SUCCESS) {
153 return APR_SUCCESS;
154 }
155 return stat;
156}
157
159{
160 return _proc_mutex_cleanup(mutex);
161}
162
163
165{
166 return NULL;
167}
168
173
175{
176 return "beossem";
177}
178
179APR_DECLARE(const char *) apr_proc_mutex_defname(void)
180{
181 return "beossem";
182}
183
185
187
188/* Implement OS-specific accessors defined in apr_portable.h */
189
193{
194 ospmutex->sem = pmutex->Lock;
195 ospmutex->ben = pmutex->LockCount;
196 if (mech) {
198 }
199 return APR_SUCCESS;
200}
201
204{
206}
207
213{
214 if (pool == NULL) {
215 return APR_ENOPOOL;
216 }
218 return APR_ENOTIMPL;
219 }
220
221 if ((*pmutex) == NULL) {
222 (*pmutex) = (apr_proc_mutex_t *)apr_pcalloc(pool, sizeof(apr_proc_mutex_t));
223 (*pmutex)->pool = pool;
224 }
225 (*pmutex)->Lock = ospmutex->sem;
226 (*pmutex)->LockCount = ospmutex->ben;
227
228 if (register_cleanup) {
231 }
232 return APR_SUCCESS;
233}
234
238{
240 0, pool);
241}
242
APR Portability Routines.
APR Strings library.
static apr_status_t _proc_mutex_cleanup(void *data)
Definition proc_mutex.c:25
static sem_id lock
Definition threadpriv.c:21
#define APR_ENOMEM
Definition apr_errno.h:683
#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
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_SUCCESS
Definition apr_errno.h:225
int apr_status_t
Definition apr_errno.h:44
void * data
const char * fname
#define APR_PERMS_SET_ENOTIMPL(type)
#define APR_POOL_IMPLEMENT_ACCESSOR(type)
Definition apr_pools.h:91
#define apr_pcalloc(p, size)
Definition apr_pools.h:465
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
apr_int64_t apr_interval_time_t
Definition apr_time.h:55
return NULL
Definition mod_so.c:359
static void proc_mutex(abts_case *tc, void *data)
IN ULONG IN INT timeout