~ubuntu-branches/ubuntu/feisty/apache2/feisty

« back to all changes in this revision

Viewing changes to srclib/apr/locks/netware/thread_rwlock.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Barth
  • Date: 2006-12-09 21:05:45 UTC
  • mfrom: (0.6.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061209210545-h70s0xaqc2v8vqr2
Tags: 2.2.3-3.2
* Non-maintainer upload.
* 043_ajp_connection_reuse: Patch from upstream Bugzilla, fixing a critical
  issue with regard to connection reuse in mod_proxy_ajp.
  Closes: #396265

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
 
2
 * applicable.
 
3
 *
 
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
 
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_general.h"
 
20
#include "apr_strings.h"
 
21
#include "apr_arch_thread_rwlock.h"
 
22
#include "apr_portable.h"
 
23
 
 
24
static apr_status_t thread_rwlock_cleanup(void *data)
 
25
{
 
26
    apr_thread_rwlock_t *rwlock = (apr_thread_rwlock_t *)data;
 
27
 
 
28
    NXRwLockFree (rwlock->rwlock);
 
29
    return APR_SUCCESS;
 
30
 
31
 
 
32
APR_DECLARE(apr_status_t) apr_thread_rwlock_create(apr_thread_rwlock_t **rwlock,
 
33
                                                   apr_pool_t *pool)
 
34
{
 
35
    apr_thread_rwlock_t *new_rwlock = NULL;
 
36
   
 
37
        NXHierarchy_t hierarchy = 1;   //for libc NKS NXRwLockAlloc
 
38
        NXLockInfo_t *info;                        //for libc NKS NXRwLockAlloc
 
39
 
 
40
    new_rwlock = (apr_thread_rwlock_t *)apr_pcalloc(pool, sizeof(apr_thread_rwlock_t));
 
41
        
 
42
        if(new_rwlock ==NULL) {
 
43
        return APR_ENOMEM;
 
44
    }     
 
45
    new_rwlock->pool = pool;
 
46
    
 
47
    info = (NXLockInfo_t *)apr_pcalloc(pool, sizeof(NXLockInfo_t));
 
48
    new_rwlock->rwlock = NXRwLockAlloc(hierarchy, info);
 
49
    if(new_rwlock->rwlock == NULL)
 
50
        return APR_ENOMEM;
 
51
 
 
52
    apr_pool_cleanup_register(new_rwlock->pool, new_rwlock, thread_rwlock_cleanup,
 
53
                              apr_pool_cleanup_null);
 
54
    *rwlock = new_rwlock;
 
55
 
 
56
    return APR_SUCCESS;
 
57
}
 
58
 
 
59
APR_DECLARE(apr_status_t) apr_thread_rwlock_rdlock(apr_thread_rwlock_t *rwlock)
 
60
{
 
61
    NXRdLock(rwlock->rwlock);
 
62
    return APR_SUCCESS;
 
63
}
 
64
 
 
65
APR_DECLARE(apr_status_t) apr_thread_rwlock_tryrdlock(apr_thread_rwlock_t *rwlock)
 
66
{
 
67
    if (!NXTryRdLock(rwlock->rwlock))
 
68
        return APR_EBUSY;
 
69
    return APR_SUCCESS;
 
70
}
 
71
 
 
72
APR_DECLARE(apr_status_t) apr_thread_rwlock_wrlock(apr_thread_rwlock_t *rwlock)
 
73
{
 
74
    NXWrLock(rwlock->rwlock);
 
75
    return APR_SUCCESS;
 
76
}
 
77
 
 
78
APR_DECLARE(apr_status_t) apr_thread_rwlock_trywrlock(apr_thread_rwlock_t *rwlock)
 
79
{
 
80
    if (!NXTryWrLock(rwlock->rwlock))
 
81
        return APR_EBUSY;
 
82
    return APR_SUCCESS;
 
83
}
 
84
 
 
85
APR_DECLARE(apr_status_t) apr_thread_rwlock_unlock(apr_thread_rwlock_t *rwlock)
 
86
{
 
87
    NXRwUnlock(rwlock->rwlock);
 
88
    return APR_SUCCESS;
 
89
}
 
90
 
 
91
APR_DECLARE(apr_status_t) apr_thread_rwlock_destroy(apr_thread_rwlock_t *rwlock)
 
92
{
 
93
    apr_status_t stat;
 
94
    if ((stat = thread_rwlock_cleanup(rwlock)) == APR_SUCCESS) {
 
95
        apr_pool_cleanup_kill(rwlock->pool, rwlock, thread_rwlock_cleanup);
 
96
        return APR_SUCCESS;
 
97
    }
 
98
    return stat;
 
99
}
 
100
 
 
101
APR_POOL_IMPLEMENT_ACCESSOR(thread_rwlock)
 
102