1
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
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.
17
#include "apr_general.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"
26
static apr_status_t thread_mutex_cleanup(void *themutex)
28
apr_thread_mutex_t *mutex = themutex;
29
return apr_thread_mutex_destroy(mutex);
34
/* XXX: Need to respect APR_THREAD_MUTEX_[UN]NESTED flags argument
35
* or return APR_ENOTIMPL!!!
37
APR_DECLARE(apr_status_t) apr_thread_mutex_create(apr_thread_mutex_t **mutex,
41
apr_thread_mutex_t *new_mutex;
44
new_mutex = (apr_thread_mutex_t *)apr_palloc(pool, sizeof(apr_thread_mutex_t));
45
new_mutex->pool = pool;
47
rc = DosCreateMutexSem(NULL, &(new_mutex->hMutex), 0, FALSE);
51
apr_pool_cleanup_register(pool, new_mutex, thread_mutex_cleanup, apr_pool_cleanup_null);
53
return APR_OS2_STATUS(rc);
58
APR_DECLARE(apr_status_t) apr_thread_mutex_lock(apr_thread_mutex_t *mutex)
60
ULONG rc = DosRequestMutexSem(mutex->hMutex, SEM_INDEFINITE_WAIT);
61
return APR_OS2_STATUS(rc);
66
APR_DECLARE(apr_status_t) apr_thread_mutex_trylock(apr_thread_mutex_t *mutex)
68
ULONG rc = DosRequestMutexSem(mutex->hMutex, SEM_IMMEDIATE_RETURN);
69
return APR_OS2_STATUS(rc);
74
APR_DECLARE(apr_status_t) apr_thread_mutex_unlock(apr_thread_mutex_t *mutex)
76
ULONG rc = DosReleaseMutexSem(mutex->hMutex);
77
return APR_OS2_STATUS(rc);
82
APR_DECLARE(apr_status_t) apr_thread_mutex_destroy(apr_thread_mutex_t *mutex)
86
if (mutex->hMutex == 0)
89
while (DosReleaseMutexSem(mutex->hMutex) == 0);
91
rc = DosCloseMutexSem(mutex->hMutex);
98
return APR_FROM_OS_ERROR(rc);
101
APR_POOL_IMPLEMENT_ACCESSOR(thread_mutex)