global_mutex.c (302408) | global_mutex.c (362181) |
---|---|
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" | 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 |
|
18#include "apr_strings.h" 19#include "apr_arch_global_mutex.h" 20#include "apr_proc_mutex.h" 21#include "apr_thread_mutex.h" 22#include "apr_portable.h" 23 24static apr_status_t global_mutex_cleanup(void *data) 25{ --- 28 unchanged lines hidden (view full) --- 54 m->pool = pool; 55 56 rv = apr_proc_mutex_create(&m->proc_mutex, fname, mech, m->pool); 57 if (rv != APR_SUCCESS) { 58 return rv; 59 } 60 61#if APR_HAS_THREADS | 19#include "apr_strings.h" 20#include "apr_arch_global_mutex.h" 21#include "apr_proc_mutex.h" 22#include "apr_thread_mutex.h" 23#include "apr_portable.h" 24 25static apr_status_t global_mutex_cleanup(void *data) 26{ --- 28 unchanged lines hidden (view full) --- 55 m->pool = pool; 56 57 rv = apr_proc_mutex_create(&m->proc_mutex, fname, mech, m->pool); 58 if (rv != APR_SUCCESS) { 59 return rv; 60 } 61 62#if APR_HAS_THREADS |
62 if (m->proc_mutex->inter_meth->flags & APR_PROCESS_LOCK_MECH_IS_GLOBAL) { | 63 if (m->proc_mutex->meth->flags & APR_PROCESS_LOCK_MECH_IS_GLOBAL) { |
63 m->thread_mutex = NULL; /* We don't need a thread lock. */ 64 } 65 else { 66 rv = apr_thread_mutex_create(&m->thread_mutex, 67 APR_THREAD_MUTEX_DEFAULT, m->pool); 68 if (rv != APR_SUCCESS) { 69 rv = apr_proc_mutex_destroy(m->proc_mutex); 70 return rv; --- 65 unchanged lines hidden (view full) --- 136 (void)apr_thread_mutex_unlock(mutex->thread_mutex); 137 } 138 } 139#endif /* APR_HAS_THREADS */ 140 141 return rv; 142} 143 | 64 m->thread_mutex = NULL; /* We don't need a thread lock. */ 65 } 66 else { 67 rv = apr_thread_mutex_create(&m->thread_mutex, 68 APR_THREAD_MUTEX_DEFAULT, m->pool); 69 if (rv != APR_SUCCESS) { 70 rv = apr_proc_mutex_destroy(m->proc_mutex); 71 return rv; --- 65 unchanged lines hidden (view full) --- 137 (void)apr_thread_mutex_unlock(mutex->thread_mutex); 138 } 139 } 140#endif /* APR_HAS_THREADS */ 141 142 return rv; 143} 144 |
145APR_DECLARE(apr_status_t) apr_global_mutex_timedlock(apr_global_mutex_t *mutex, 146 apr_interval_time_t timeout) 147{ 148#if APR_HAS_TIMEDLOCKS 149 apr_status_t rv; 150 151#if APR_HAS_THREADS 152 if (mutex->thread_mutex) { 153 apr_time_t expiry = 0; 154 if (timeout > 0) { 155 expiry = apr_time_now() + timeout; 156 } 157 rv = apr_thread_mutex_timedlock(mutex->thread_mutex, timeout); 158 if (rv != APR_SUCCESS) { 159 return rv; 160 } 161 if (expiry) { 162 timeout = expiry - apr_time_now(); 163 if (timeout < 0) { 164 timeout = 0; 165 } 166 } 167 } 168#endif /* APR_HAS_THREADS */ 169 170 rv = apr_proc_mutex_timedlock(mutex->proc_mutex, timeout); 171 172#if APR_HAS_THREADS 173 if (rv != APR_SUCCESS) { 174 if (mutex->thread_mutex) { 175 (void)apr_thread_mutex_unlock(mutex->thread_mutex); 176 } 177 } 178#endif /* APR_HAS_THREADS */ 179 180 return rv; 181#else /* APR_HAS_TIMEDLOCKS */ 182 return APR_ENOTIMPL; 183#endif 184} 185 |
|
144APR_DECLARE(apr_status_t) apr_global_mutex_unlock(apr_global_mutex_t *mutex) 145{ 146 apr_status_t rv; 147 148 rv = apr_proc_mutex_unlock(mutex->proc_mutex); 149#if APR_HAS_THREADS 150 if (mutex->thread_mutex) { 151 if (rv != APR_SUCCESS) { --- 23 unchanged lines hidden (view full) --- 175 return apr_pool_cleanup_run(mutex->pool, mutex, global_mutex_cleanup); 176} 177 178APR_DECLARE(const char *) apr_global_mutex_lockfile(apr_global_mutex_t *mutex) 179{ 180 return apr_proc_mutex_lockfile(mutex->proc_mutex); 181} 182 | 186APR_DECLARE(apr_status_t) apr_global_mutex_unlock(apr_global_mutex_t *mutex) 187{ 188 apr_status_t rv; 189 190 rv = apr_proc_mutex_unlock(mutex->proc_mutex); 191#if APR_HAS_THREADS 192 if (mutex->thread_mutex) { 193 if (rv != APR_SUCCESS) { --- 23 unchanged lines hidden (view full) --- 217 return apr_pool_cleanup_run(mutex->pool, mutex, global_mutex_cleanup); 218} 219 220APR_DECLARE(const char *) apr_global_mutex_lockfile(apr_global_mutex_t *mutex) 221{ 222 return apr_proc_mutex_lockfile(mutex->proc_mutex); 223} 224 |
225APR_DECLARE(apr_lockmech_e) apr_global_mutex_mech(apr_global_mutex_t *mutex) 226{ 227 return apr_proc_mutex_mech(mutex->proc_mutex); 228} 229 |
|
183APR_DECLARE(const char *) apr_global_mutex_name(apr_global_mutex_t *mutex) 184{ 185 return apr_proc_mutex_name(mutex->proc_mutex); 186} 187 | 230APR_DECLARE(const char *) apr_global_mutex_name(apr_global_mutex_t *mutex) 231{ 232 return apr_proc_mutex_name(mutex->proc_mutex); 233} 234 |
235APR_PERMS_SET_IMPLEMENT(global_mutex) 236{ 237 apr_status_t rv; 238 apr_global_mutex_t *mutex = (apr_global_mutex_t *)theglobal_mutex; 239 240 rv = APR_PERMS_SET_FN(proc_mutex)(mutex->proc_mutex, perms, uid, gid); 241 return rv; 242} 243 |
|
188APR_POOL_IMPLEMENT_ACCESSOR(global_mutex) | 244APR_POOL_IMPLEMENT_ACCESSOR(global_mutex) |
245 |
|