upload http
[bottlenecks.git] / rubbos / app / httpd-2.0.64 / srclib / apr / include / apr_thread_rwlock.h
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 #ifndef APR_THREAD_RWLOCK_H
18 #define APR_THREAD_RWLOCK_H
19
20 /**
21  * @file apr_thread_rwlock.h
22  * @brief APR Reader/Writer Lock Routines
23  */
24
25 #include "apr.h"
26 #include "apr_pools.h"
27 #include "apr_errno.h"
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif /* __cplusplus */
32
33 #if APR_HAS_THREADS
34
35 /**
36  * @defgroup apr_thread_rwlock Reader/Writer Lock Routines
37  * @ingroup APR 
38  * @{
39  */
40
41 /** Opaque read-write thread-safe lock. */
42 typedef struct apr_thread_rwlock_t apr_thread_rwlock_t;
43
44 /**
45  * Create and initialize a read-write lock that can be used to synchronize
46  * threads.
47  * @param rwlock the memory address where the newly created readwrite lock
48  *        will be stored.
49  * @param pool the pool from which to allocate the mutex.
50  */
51 APR_DECLARE(apr_status_t) apr_thread_rwlock_create(apr_thread_rwlock_t **rwlock,
52                                                    apr_pool_t *pool);
53 /**
54  * Acquire a shared-read lock on the given read-write lock. This will allow
55  * multiple threads to enter the same critical section while they have acquired
56  * the read lock.
57  * @param rwlock the read-write lock on which to acquire the shared read.
58  */
59 APR_DECLARE(apr_status_t) apr_thread_rwlock_rdlock(apr_thread_rwlock_t *rwlock);
60
61 /**
62  * Attempt to acquire the shread-read lock on the given read-write lock. This
63  * is the same as apr_thread_rwlock_rdlock(), only that the funtion fails
64  * if there is another thread holding the write lock, or if there are any
65  * write threads blocking on the lock. If the function failes for this case,
66  * APR_EBUSY will be returned. Note: it is important that the
67  * APR_STATUS_IS_EBUSY(s) macro be used to determine if the return value was
68  * APR_EBUSY, for portability reasons.
69  * @param rwlock the rwlock on which to attempt the shared read.
70  */
71 APR_DECLARE(apr_status_t) apr_thread_rwlock_tryrdlock(apr_thread_rwlock_t *rwlock);
72
73 /**
74  * Acquire an exclusive-write lock on the given read-write lock. This will
75  * allow only one single thread to enter the critical sections. If there
76  * are any threads currently holding thee read-lock, this thread is put to
77  * sleep until it can have exclusive access to the lock.
78  * @param rwlock the read-write lock on which to acquire the exclusive write.
79  */
80 APR_DECLARE(apr_status_t) apr_thread_rwlock_wrlock(apr_thread_rwlock_t *rwlock);
81
82 /**
83  * Attempt to acquire the exclusive-write lock on the given read-write lock. 
84  * This is the same as apr_thread_rwlock_wrlock(), only that the funtion fails
85  * if there is any other thread holding the lock (for reading or writing),
86  * in which case the function will return APR_EBUSY. Note: it is important
87  * that the APR_STATUS_IS_EBUSY(s) macro be used to determine if the return
88  * value was APR_EBUSY, for portability reasons.
89  * @param rwlock the rwlock on which to attempt the exclusive write.
90  */
91 APR_DECLARE(apr_status_t) apr_thread_rwlock_trywrlock(apr_thread_rwlock_t *rwlock);
92
93 /**
94  * Release either the read or write lock currently held by the calling thread
95  * associated with the given read-write lock.
96  * @param rwlock the read-write lock to be released (unlocked).
97  */
98 APR_DECLARE(apr_status_t) apr_thread_rwlock_unlock(apr_thread_rwlock_t *rwlock);
99
100 /**
101  * Destroy the read-write lock and free the associated memory.
102  * @param rwlock the rwlock to destroy.
103  */
104 APR_DECLARE(apr_status_t) apr_thread_rwlock_destroy(apr_thread_rwlock_t *rwlock);
105
106 /**
107  * Get the pool used by this thread_rwlock.
108  * @return apr_pool_t the pool
109  */
110 APR_POOL_DECLARE_ACCESSOR(thread_rwlock);
111
112 #endif  /* APR_HAS_THREADS */
113
114 /** @} */
115
116 #ifdef __cplusplus
117 }
118 #endif
119
120 #endif  /* ! APR_THREAD_RWLOCK_H */