"Fossies" - the Fresh Open Source Software Archive 
Member "apr-1.7.0/locks/os2/thread_mutex.c" (7 Apr 2017, 3303 Bytes) of package /linux/www/apr-1.7.0.tar.bz2:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "thread_mutex.c" see the
Fossies "Dox" file reference documentation and the latest
Fossies "Diffs" side-by-side code changes report:
1.6.5_vs_1.7.0.
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_mutex.h"
22 #include "apr_arch_file_io.h"
23 #include <string.h>
24 #include <stddef.h>
25
26 static apr_status_t thread_mutex_cleanup(void *themutex)
27 {
28 apr_thread_mutex_t *mutex = themutex;
29 return apr_thread_mutex_destroy(mutex);
30 }
31
32
33
34 /* XXX: Need to respect APR_THREAD_MUTEX_[UN]NESTED flags argument
35 * or return APR_ENOTIMPL!!!
36 */
37 APR_DECLARE(apr_status_t) apr_thread_mutex_create(apr_thread_mutex_t **mutex,
38 unsigned int flags,
39 apr_pool_t *pool)
40 {
41 apr_thread_mutex_t *new_mutex;
42 ULONG rc;
43
44 new_mutex = (apr_thread_mutex_t *)apr_palloc(pool, sizeof(apr_thread_mutex_t));
45 new_mutex->pool = pool;
46
47 rc = DosCreateMutexSem(NULL, &(new_mutex->hMutex), 0, FALSE);
48 *mutex = new_mutex;
49
50 if (!rc)
51 apr_pool_cleanup_register(pool, new_mutex, thread_mutex_cleanup, apr_pool_cleanup_null);
52
53 return APR_OS2_STATUS(rc);
54 }
55
56
57
58 APR_DECLARE(apr_status_t) apr_thread_mutex_lock(apr_thread_mutex_t *mutex)
59 {
60 ULONG rc = DosRequestMutexSem(mutex->hMutex, SEM_INDEFINITE_WAIT);
61 return APR_OS2_STATUS(rc);
62 }
63
64
65
66 APR_DECLARE(apr_status_t) apr_thread_mutex_trylock(apr_thread_mutex_t *mutex)
67 {
68 ULONG rc = DosRequestMutexSem(mutex->hMutex, SEM_IMMEDIATE_RETURN);
69
70 return (rc == ERROR_TIMEOUT) ? APR_EBUSY : APR_FROM_OS_ERROR(rc);
71 }
72
73
74
75 APR_DECLARE(apr_status_t) apr_thread_mutex_timedlock(apr_thread_mutex_t *mutex,
76 apr_interval_time_t timeout)
77 {
78 ULONG rc;
79
80 if (timeout <= 0) {
81 rc = DosRequestMutexSem(mutex->hMutex, SEM_IMMEDIATE_RETURN);
82 }
83 else {
84 rc = DosRequestMutexSem(mutex->hMutex, apr_time_as_msec(timeout));
85 }
86
87 return (rc == ERROR_TIMEOUT) ? APR_TIMEUP : APR_FROM_OS_ERROR(rc);
88 }
89
90
91
92 APR_DECLARE(apr_status_t) apr_thread_mutex_unlock(apr_thread_mutex_t *mutex)
93 {
94 ULONG rc = DosReleaseMutexSem(mutex->hMutex);
95 return APR_OS2_STATUS(rc);
96 }
97
98
99
100 APR_DECLARE(apr_status_t) apr_thread_mutex_destroy(apr_thread_mutex_t *mutex)
101 {
102 ULONG rc;
103
104 if (mutex->hMutex == 0)
105 return APR_SUCCESS;
106
107 while (DosReleaseMutexSem(mutex->hMutex) == 0);
108
109 rc = DosCloseMutexSem(mutex->hMutex);
110
111 if (!rc) {
112 mutex->hMutex = 0;
113 return APR_SUCCESS;
114 }
115
116 return APR_FROM_OS_ERROR(rc);
117 }
118
119 APR_POOL_IMPLEMENT_ACCESSOR(thread_mutex)
120