Apache HTTPD
thread_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.h"
18#include "apr_private.h"
19#include "apr_general.h"
20#include "apr_strings.h"
21#include "apr_arch_thread_mutex.h"
22#include "apr_thread_cond.h"
23#include "apr_portable.h"
24
26{
28
29 NXMutexFree(mutex->mutex);
30 return APR_SUCCESS;
31}
32
34 unsigned int flags,
36{
38
39 /* XXX: Implement _UNNESTED flavor and favor _DEFAULT for performance
40 */
42 return APR_ENOTIMPL;
43 }
45
46 if (new_mutex == NULL) {
47 return APR_ENOMEM;
48 }
50
52
53 if(new_mutex->mutex == NULL)
54 return APR_ENOMEM;
55
58 if (rv != APR_SUCCESS) {
59 NXMutexFree(new_mutex->mutex);
60 return rv;
61 }
62 }
63
67 *mutex = new_mutex;
68 return APR_SUCCESS;
69}
70
72{
73 if (mutex->cond) {
74 apr_status_t rv;
75 NXLock(mutex->mutex);
76 if (mutex->locked) {
77 mutex->num_waiters++;
78 rv = apr_thread_cond_wait(mutex->cond, mutex);
79 mutex->num_waiters--;
80 }
81 else {
82 mutex->locked = 1;
83 rv = APR_SUCCESS;
84 }
85 NXUnlock(mutex->mutex);
86 return rv;
87 }
88
89 NXLock(mutex->mutex);
90 return APR_SUCCESS;
91}
92
94{
95 if (mutex->cond) {
96 apr_status_t rv;
97 NXLock(mutex->mutex);
98 if (mutex->locked) {
99 rv = APR_EBUSY;
100 }
101 else {
102 mutex->locked = 1;
103 rv = APR_SUCCESS;
104 }
105 NXUnlock(mutex->mutex);
106 return rv;
107 }
108
109 if (!NXTryLock(mutex->mutex))
110 return APR_EBUSY;
111 return APR_SUCCESS;
112}
113
116{
117 if (mutex->cond) {
119
120 NXLock(mutex->mutex);
121 if (mutex->locked) {
122 if (timeout <= 0) {
123 rv = APR_TIMEUP;
124 }
125 else {
126 mutex->num_waiters++;
127 do {
128 rv = apr_thread_cond_timedwait(mutex->cond, mutex,
129 timeout);
130 } while (rv == APR_SUCCESS && mutex->locked);
131 mutex->num_waiters--;
132 }
133 }
134 if (rv == APR_SUCCESS) {
135 mutex->locked = 1;
136 }
137 NXUnlock(mutex->mutex);
138 return rv;
139 }
140
141 return APR_ENOTIMPL;
142}
143
145{
147
148 if (mutex->cond) {
149 NXLock(mutex->mutex);
150
151 if (!mutex->locked) {
152 rv = APR_EINVAL;
153 }
154 else if (mutex->num_waiters) {
155 rv = apr_thread_cond_signal(mutex->cond);
156 }
157 if (rv == APR_SUCCESS) {
158 mutex->locked = 0;
159 }
160 }
161
162 NXUnlock(mutex->mutex);
163 return rv;
164}
165
167{
169 if (mutex->cond) {
170 rv = apr_thread_cond_destroy(mutex->cond);
171 mutex->cond = NULL;
172 }
174 if (stat == APR_SUCCESS && rv) {
175 stat = rv;
176 }
177 return stat;
178}
179
181
APR Miscellaneous library routines.
APR Portability Routines.
APR Strings library.
APR Condition Variable Routines.
#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_EBUSY
Definition apr_errno.h:480
#define APR_EINVAL
Definition apr_errno.h:711
const char apr_ssize_t int flags
Definition apr_encode.h:168
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
#define APR_POOL_IMPLEMENT_ACCESSOR(type)
Definition apr_pools.h:91
#define apr_pcalloc(p, size)
Definition apr_pools.h:465
apr_int64_t apr_interval_time_t
Definition apr_time.h:55
return NULL
Definition mod_so.c:359
static apr_status_t thread_mutex_cleanup(void *data)
apr_thread_cond_t * cond
IN ULONG IN INT timeout