00001 /* Copyright 2000-2005 The Apache Software Foundation or its licensors, as 00002 * applicable. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef APR_THREAD_RWLOCK_H 00018 #define APR_THREAD_RWLOCK_H 00019 00020 /** 00021 * @file apr_thread_rwlock.h 00022 * @brief APR Reader/Writer Lock Routines 00023 */ 00024 00025 #include "apr.h" 00026 #include "apr_pools.h" 00027 #include "apr_errno.h" 00028 00029 #ifdef __cplusplus 00030 extern "C" { 00031 #endif /* __cplusplus */ 00032 00033 #if APR_HAS_THREADS 00034 00035 /** 00036 * @defgroup apr_thread_rwlock Reader/Writer Lock Routines 00037 * @ingroup APR 00038 * @{ 00039 */ 00040 00041 /** Opaque read-write thread-safe lock. */ 00042 typedef struct apr_thread_rwlock_t apr_thread_rwlock_t; 00043 00044 /** 00045 * Create and initialize a read-write lock that can be used to synchronize 00046 * threads. 00047 * @param rwlock the memory address where the newly created readwrite lock 00048 * will be stored. 00049 * @param pool the pool from which to allocate the mutex. 00050 */ 00051 APR_DECLARE(apr_status_t) apr_thread_rwlock_create(apr_thread_rwlock_t **rwlock, 00052 apr_pool_t *pool); 00053 /** 00054 * Acquire a shared-read lock on the given read-write lock. This will allow 00055 * multiple threads to enter the same critical section while they have acquired 00056 * the read lock. 00057 * @param rwlock the read-write lock on which to acquire the shared read. 00058 */ 00059 APR_DECLARE(apr_status_t) apr_thread_rwlock_rdlock(apr_thread_rwlock_t *rwlock); 00060 00061 /** 00062 * Attempt to acquire the shread-read lock on the given read-write lock. This 00063 * is the same as apr_thread_rwlock_rdlock(), only that the funtion fails 00064 * if there is another thread holding the write lock, or if there are any 00065 * write threads blocking on the lock. If the function failes for this case, 00066 * APR_EBUSY will be returned. Note: it is important that the 00067 * APR_STATUS_IS_EBUSY(s) macro be used to determine if the return value was 00068 * APR_EBUSY, for portability reasons. 00069 * @param rwlock the rwlock on which to attempt the shared read. 00070 */ 00071 APR_DECLARE(apr_status_t) apr_thread_rwlock_tryrdlock(apr_thread_rwlock_t *rwlock); 00072 00073 /** 00074 * Acquire an exclusive-write lock on the given read-write lock. This will 00075 * allow only one single thread to enter the critical sections. If there 00076 * are any threads currently holding thee read-lock, this thread is put to 00077 * sleep until it can have exclusive access to the lock. 00078 * @param rwlock the read-write lock on which to acquire the exclusive write. 00079 */ 00080 APR_DECLARE(apr_status_t) apr_thread_rwlock_wrlock(apr_thread_rwlock_t *rwlock); 00081 00082 /** 00083 * Attempt to acquire the exclusive-write lock on the given read-write lock. 00084 * This is the same as apr_thread_rwlock_wrlock(), only that the funtion fails 00085 * if there is any other thread holding the lock (for reading or writing), 00086 * in which case the function will return APR_EBUSY. Note: it is important 00087 * that the APR_STATUS_IS_EBUSY(s) macro be used to determine if the return 00088 * value was APR_EBUSY, for portability reasons. 00089 * @param rwlock the rwlock on which to attempt the exclusive write. 00090 */ 00091 APR_DECLARE(apr_status_t) apr_thread_rwlock_trywrlock(apr_thread_rwlock_t *rwlock); 00092 00093 /** 00094 * Release either the read or write lock currently held by the calling thread 00095 * associated with the given read-write lock. 00096 * @param rwlock the read-write lock to be released (unlocked). 00097 */ 00098 APR_DECLARE(apr_status_t) apr_thread_rwlock_unlock(apr_thread_rwlock_t *rwlock); 00099 00100 /** 00101 * Destroy the read-write lock and free the associated memory. 00102 * @param rwlock the rwlock to destroy. 00103 */ 00104 APR_DECLARE(apr_status_t) apr_thread_rwlock_destroy(apr_thread_rwlock_t *rwlock); 00105 00106 /** 00107 * Get the pool used by this thread_rwlock. 00108 * @return apr_pool_t the pool 00109 */ 00110 APR_POOL_DECLARE_ACCESSOR(thread_rwlock); 00111 00112 #endif /* APR_HAS_THREADS */ 00113 00114 /** @} */ 00115 00116 #ifdef __cplusplus 00117 } 00118 #endif 00119 00120 #endif /* ! APR_THREAD_RWLOCK_H */