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
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.
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_portable.h"
24 static apr_status_t thread_mutex_cleanup(void *data)
26 apr_thread_mutex_t *mutex = (apr_thread_mutex_t *)data;
28 NXMutexFree(mutex->mutex);
32 APR_DECLARE(apr_status_t) apr_thread_mutex_create(apr_thread_mutex_t **mutex,
36 apr_thread_mutex_t *new_mutex = NULL;
38 /* XXX: Implement _UNNESTED flavor and favor _DEFAULT for performance
40 if (flags & APR_THREAD_MUTEX_UNNESTED) {
43 new_mutex = (apr_thread_mutex_t *)apr_pcalloc(pool, sizeof(apr_thread_mutex_t));
45 if(new_mutex ==NULL) {
48 new_mutex->pool = pool;
50 new_mutex->mutex = NXMutexAlloc(NX_MUTEX_RECURSIVE, 0, NULL);
52 if(new_mutex->mutex == NULL)
55 apr_pool_cleanup_register(new_mutex->pool, new_mutex,
56 (void*)thread_mutex_cleanup,
57 apr_pool_cleanup_null);
62 APR_DECLARE(apr_status_t) apr_thread_mutex_lock(apr_thread_mutex_t *mutex)
68 APR_DECLARE(apr_status_t) apr_thread_mutex_trylock(apr_thread_mutex_t *mutex)
70 if (!NXTryLock(mutex->mutex))
75 APR_DECLARE(apr_status_t) apr_thread_mutex_unlock(apr_thread_mutex_t *mutex)
77 NXUnlock(mutex->mutex);
81 APR_DECLARE(apr_status_t) apr_thread_mutex_destroy(apr_thread_mutex_t *mutex)
84 if ((stat = thread_mutex_cleanup(mutex)) == APR_SUCCESS) {
85 apr_pool_cleanup_kill(mutex->pool, mutex, thread_mutex_cleanup);
91 APR_POOL_IMPLEMENT_ACCESSOR(thread_mutex)