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_portable.h"
20 #include "apr_arch_proc_mutex.h"
21 #include "apr_arch_thread_mutex.h"
22
apr_proc_mutex_create(apr_proc_mutex_t ** mutex,const char * fname,apr_lockmech_e mech,apr_pool_t * pool)23 APR_DECLARE(apr_status_t) apr_proc_mutex_create(apr_proc_mutex_t **mutex,
24 const char *fname,
25 apr_lockmech_e mech,
26 apr_pool_t *pool)
27 {
28 apr_status_t ret;
29 apr_proc_mutex_t *new_mutex = NULL;
30 new_mutex = (apr_proc_mutex_t *)apr_pcalloc(pool, sizeof(apr_proc_mutex_t));
31
32 if(new_mutex ==NULL) {
33 return APR_ENOMEM;
34 }
35
36 new_mutex->pool = pool;
37 ret = apr_thread_mutex_create(&(new_mutex->mutex), APR_THREAD_MUTEX_DEFAULT, pool);
38
39 if (ret == APR_SUCCESS)
40 *mutex = new_mutex;
41
42 return ret;
43 }
44
apr_proc_mutex_child_init(apr_proc_mutex_t ** mutex,const char * fname,apr_pool_t * pool)45 APR_DECLARE(apr_status_t) apr_proc_mutex_child_init(apr_proc_mutex_t **mutex,
46 const char *fname,
47 apr_pool_t *pool)
48 {
49 return APR_SUCCESS;
50 }
51
apr_proc_mutex_lock(apr_proc_mutex_t * mutex)52 APR_DECLARE(apr_status_t) apr_proc_mutex_lock(apr_proc_mutex_t *mutex)
53 {
54 if (mutex)
55 return apr_thread_mutex_lock(mutex->mutex);
56 return APR_ENOLOCK;
57 }
58
apr_proc_mutex_trylock(apr_proc_mutex_t * mutex)59 APR_DECLARE(apr_status_t) apr_proc_mutex_trylock(apr_proc_mutex_t *mutex)
60 {
61 if (mutex)
62 return apr_thread_mutex_trylock(mutex->mutex);
63 return APR_ENOLOCK;
64 }
65
apr_proc_mutex_unlock(apr_proc_mutex_t * mutex)66 APR_DECLARE(apr_status_t) apr_proc_mutex_unlock(apr_proc_mutex_t *mutex)
67 {
68 if (mutex)
69 return apr_thread_mutex_unlock(mutex->mutex);
70 return APR_ENOLOCK;
71 }
72
apr_proc_mutex_cleanup(void * mutex)73 APR_DECLARE(apr_status_t) apr_proc_mutex_cleanup(void *mutex)
74 {
75 return apr_proc_mutex_destroy(mutex);
76 }
77
apr_proc_mutex_destroy(apr_proc_mutex_t * mutex)78 APR_DECLARE(apr_status_t) apr_proc_mutex_destroy(apr_proc_mutex_t *mutex)
79 {
80 if (mutex)
81 return apr_thread_mutex_destroy(mutex->mutex);
82 return APR_ENOLOCK;
83 }
84
apr_proc_mutex_lockfile(apr_proc_mutex_t * mutex)85 APR_DECLARE(const char *) apr_proc_mutex_lockfile(apr_proc_mutex_t *mutex)
86 {
87 return NULL;
88 }
89
apr_proc_mutex_name(apr_proc_mutex_t * mutex)90 APR_DECLARE(const char *) apr_proc_mutex_name(apr_proc_mutex_t *mutex)
91 {
92 return "netwarethread";
93 }
94
apr_proc_mutex_defname(void)95 APR_DECLARE(const char *) apr_proc_mutex_defname(void)
96 {
97 return "netwarethread";
98 }
99
APR_POOL_IMPLEMENT_ACCESSOR(proc_mutex)100 APR_POOL_IMPLEMENT_ACCESSOR(proc_mutex)
101
102 /* Implement OS-specific accessors defined in apr_portable.h */
103
104 apr_status_t apr_os_proc_mutex_get(apr_os_proc_mutex_t *ospmutex,
105 apr_proc_mutex_t *pmutex)
106 {
107 if (pmutex)
108 ospmutex = pmutex->mutex->mutex;
109 return APR_ENOLOCK;
110 }
111
apr_os_proc_mutex_put(apr_proc_mutex_t ** pmutex,apr_os_proc_mutex_t * ospmutex,apr_pool_t * pool)112 apr_status_t apr_os_proc_mutex_put(apr_proc_mutex_t **pmutex,
113 apr_os_proc_mutex_t *ospmutex,
114 apr_pool_t *pool)
115 {
116 return APR_ENOTIMPL;
117 }
118
119