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_rwlock.h"
22 #include "apr_portable.h"
24 static apr_status_t thread_rwlock_cleanup(void *data)
26 apr_thread_rwlock_t *rwlock = (apr_thread_rwlock_t *)data;
28 NXRwLockFree (rwlock->rwlock);
32 APR_DECLARE(apr_status_t) apr_thread_rwlock_create(apr_thread_rwlock_t **rwlock,
35 apr_thread_rwlock_t *new_rwlock = NULL;
37 NXHierarchy_t hierarchy = 1; //for libc NKS NXRwLockAlloc
38 NXLockInfo_t *info; //for libc NKS NXRwLockAlloc
40 new_rwlock = (apr_thread_rwlock_t *)apr_pcalloc(pool, sizeof(apr_thread_rwlock_t));
42 if(new_rwlock ==NULL) {
45 new_rwlock->pool = pool;
47 info = (NXLockInfo_t *)apr_pcalloc(pool, sizeof(NXLockInfo_t));
48 new_rwlock->rwlock = NXRwLockAlloc(hierarchy, info);
49 if(new_rwlock->rwlock == NULL)
52 apr_pool_cleanup_register(new_rwlock->pool, new_rwlock, thread_rwlock_cleanup,
53 apr_pool_cleanup_null);
59 APR_DECLARE(apr_status_t) apr_thread_rwlock_rdlock(apr_thread_rwlock_t *rwlock)
61 NXRdLock(rwlock->rwlock);
65 APR_DECLARE(apr_status_t) apr_thread_rwlock_tryrdlock(apr_thread_rwlock_t *rwlock)
67 if (!NXTryRdLock(rwlock->rwlock))
72 APR_DECLARE(apr_status_t) apr_thread_rwlock_wrlock(apr_thread_rwlock_t *rwlock)
74 NXWrLock(rwlock->rwlock);
78 APR_DECLARE(apr_status_t) apr_thread_rwlock_trywrlock(apr_thread_rwlock_t *rwlock)
80 if (!NXTryWrLock(rwlock->rwlock))
85 APR_DECLARE(apr_status_t) apr_thread_rwlock_unlock(apr_thread_rwlock_t *rwlock)
87 NXRwUnlock(rwlock->rwlock);
91 APR_DECLARE(apr_status_t) apr_thread_rwlock_destroy(apr_thread_rwlock_t *rwlock)
94 if ((stat = thread_rwlock_cleanup(rwlock)) == APR_SUCCESS) {
95 apr_pool_cleanup_kill(rwlock->pool, rwlock, thread_rwlock_cleanup);
101 APR_POOL_IMPLEMENT_ACCESSOR(thread_rwlock)