Apache HTTPD
thread_rwlock.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_thread_rwlock.h"
22#include "apr_arch_file_io.h"
23#include <string.h>
24
30
31
32
61
62
63
65{
66 ULONG rc, posts;
67
69
70 if (rc)
71 return APR_FROM_OS_ERROR(rc);
72
73 /* We've successfully acquired the writer mutex so we can't be locked
74 * for write which means it's ok to add a reader lock. The writer mutex
75 * doubles as race condition protection for the readers counter.
76 */
77 rwlock->readers++;
80 return APR_FROM_OS_ERROR(rc);
81}
82
83
84
86{
87 /* As above but with different wait time */
88 ULONG rc, posts;
89
91
92 if (rc)
93 return APR_FROM_OS_ERROR(rc);
94
95 rwlock->readers++;
98 return APR_FROM_OS_ERROR(rc);
99}
100
101
102
104{
105 ULONG rc;
106
108
109 if (rc)
110 return APR_FROM_OS_ERROR(rc);
111
112 /* We've got the writer lock but we have to wait for all readers to
113 * unlock before it's ok to use it
114 */
115
116 if (rwlock->readers) {
118
119 if (rc)
121 }
122
123 return APR_FROM_OS_ERROR(rc);
124}
125
126
127
129{
130 ULONG rc;
131
133
134 if (rc)
135 return APR_FROM_OS_ERROR(rc);
136
137 /* We've got the writer lock but we have to wait for all readers to
138 * unlock before it's ok to use it
139 */
140
141 if (rwlock->readers) {
142 /* There are readers active, give up */
145 }
146
147 return APR_FROM_OS_ERROR(rc);
148}
149
150
151
153{
154 ULONG rc;
155
156 /* First, guess that we're unlocking a writer */
158
159 if (rc == ERROR_NOT_OWNER) {
160 /* Nope, we must have a read lock */
161 if (rwlock->readers) {
163 rwlock->readers--;
164
165 if (rwlock->readers == 0) {
166 DosPostEventSem(rwlock->read_done);
167 }
168
170 rc = 0;
171 }
172 }
173
174 return APR_FROM_OS_ERROR(rc);
175}
176
177
178
180{
181 ULONG rc;
182
183 if (rwlock->write_lock == 0)
184 return APR_SUCCESS;
185
186 while (DosReleaseMutexSem(rwlock->write_lock) == 0);
187
188 rc = DosCloseMutexSem(rwlock->write_lock);
189
190 if (!rc) {
191 rwlock->write_lock = 0;
193 return APR_SUCCESS;
194 }
195
196 return APR_FROM_OS_ERROR(rc);
197}
198
200
#define FALSE
Definition abts.h:35
APR Miscellaneous library routines.
APR general purpose library routines.
APR Portability Routines.
APR Strings library.
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
#define APR_POOL_IMPLEMENT_ACCESSOR(type)
Definition apr_pools.h:91
return NULL
Definition mod_so.c:359
static apr_status_t thread_rwlock_cleanup(void *data)
apr_thread_rwlock_tryrdlock(apr_thread_rwlock_t *rwlock)