Main Page | Modules | Namespace List | Data Structures | File List | Data Fields | Globals | Related Pages

/usr/src/rpmbuilder/BUILD/apr-util-APU_0_9_BRANCH/include/apr_anylock.h

Go to the documentation of this file.
00001 /* Copyright 2000-2004 The Apache Software Foundation
00002  *
00003  * Licensed under the Apache License, Version 2.0 (the "License");
00004  * you may not use this file except in compliance with the License.
00005  * You may obtain a copy of the License at
00006  *
00007  *     http://www.apache.org/licenses/LICENSE-2.0
00008  *
00009  * Unless required by applicable law or agreed to in writing, software
00010  * distributed under the License is distributed on an "AS IS" BASIS,
00011  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00012  * See the License for the specific language governing permissions and
00013  * limitations under the License.
00014  */
00015 
00020 #ifndef APR_ANYLOCK_H
00021 #define APR_ANYLOCK_H
00022 
00023 #include "apr_proc_mutex.h"
00024 #include "apr_thread_mutex.h"
00025 #include "apr_thread_rwlock.h"
00026 
00028 typedef struct apr_anylock_t {
00030     enum tm_lock {
00031         apr_anylock_none,           
00032         apr_anylock_procmutex,      
00033         apr_anylock_threadmutex,    
00034         apr_anylock_readlock,       
00035         apr_anylock_writelock       
00036     } type;
00038     union apr_anylock_u_t {
00039         apr_proc_mutex_t *pm;       
00040 #if APR_HAS_THREADS
00041         apr_thread_mutex_t *tm;     
00042         apr_thread_rwlock_t *rw;    
00043 #endif
00044     } lock;
00045 } apr_anylock_t;
00046 
00047 #if APR_HAS_THREADS
00048 
00050 #define APR_ANYLOCK_LOCK(lck)                \
00051     (((lck)->type == apr_anylock_none)         \
00052       ? APR_SUCCESS                              \
00053       : (((lck)->type == apr_anylock_threadmutex)  \
00054           ? apr_thread_mutex_lock((lck)->lock.tm)    \
00055           : (((lck)->type == apr_anylock_procmutex)    \
00056               ? apr_proc_mutex_lock((lck)->lock.pm)      \
00057               : (((lck)->type == apr_anylock_readlock)     \
00058                   ? apr_thread_rwlock_rdlock((lck)->lock.rw) \
00059                   : (((lck)->type == apr_anylock_writelock)    \
00060                       ? apr_thread_rwlock_wrlock((lck)->lock.rw) \
00061                       : APR_EINVAL)))))
00062 
00063 #else /* APR_HAS_THREADS */
00064 
00065 #define APR_ANYLOCK_LOCK(lck)                \
00066     (((lck)->type == apr_anylock_none)         \
00067       ? APR_SUCCESS                              \
00068           : (((lck)->type == apr_anylock_procmutex)    \
00069               ? apr_proc_mutex_lock((lck)->lock.pm)      \
00070                       : APR_EINVAL))
00071 
00072 #endif /* APR_HAS_THREADS */
00073 
00074 #if APR_HAS_THREADS
00075 
00077 #define APR_ANYLOCK_TRYLOCK(lck)                \
00078     (((lck)->type == apr_anylock_none)            \
00079       ? APR_SUCCESS                                 \
00080       : (((lck)->type == apr_anylock_threadmutex)     \
00081           ? apr_thread_mutex_trylock((lck)->lock.tm)    \
00082           : (((lck)->type == apr_anylock_procmutex)       \
00083               ? apr_proc_mutex_trylock((lck)->lock.pm)      \
00084               : (((lck)->type == apr_anylock_readlock)        \
00085                   ? apr_thread_rwlock_tryrdlock((lck)->lock.rw) \
00086                   : (((lck)->type == apr_anylock_writelock)       \
00087                       ? apr_thread_rwlock_trywrlock((lck)->lock.rw) \
00088                           : APR_EINVAL)))))
00089 
00090 #else /* APR_HAS_THREADS */
00091 
00092 #define APR_ANYLOCK_TRYLOCK(lck)                \
00093     (((lck)->type == apr_anylock_none)            \
00094       ? APR_SUCCESS                                 \
00095           : (((lck)->type == apr_anylock_procmutex)       \
00096               ? apr_proc_mutex_trylock((lck)->lock.pm)      \
00097                           : APR_EINVAL))
00098 
00099 #endif /* APR_HAS_THREADS */
00100 
00101 #if APR_HAS_THREADS
00102 
00104 #define APR_ANYLOCK_UNLOCK(lck)              \
00105     (((lck)->type == apr_anylock_none)         \
00106       ? APR_SUCCESS                              \
00107       : (((lck)->type == apr_anylock_threadmutex)  \
00108           ? apr_thread_mutex_unlock((lck)->lock.tm)  \
00109           : (((lck)->type == apr_anylock_procmutex)    \
00110               ? apr_proc_mutex_unlock((lck)->lock.pm)    \
00111               : ((((lck)->type == apr_anylock_readlock) || \
00112                   ((lck)->type == apr_anylock_writelock))    \
00113                   ? apr_thread_rwlock_unlock((lck)->lock.rw)   \
00114                       : APR_EINVAL))))
00115 
00116 #else /* APR_HAS_THREADS */
00117 
00118 #define APR_ANYLOCK_UNLOCK(lck)              \
00119     (((lck)->type == apr_anylock_none)         \
00120       ? APR_SUCCESS                              \
00121           : (((lck)->type == apr_anylock_procmutex)    \
00122               ? apr_proc_mutex_unlock((lck)->lock.pm)    \
00123                       : APR_EINVAL))
00124 
00125 #endif /* APR_HAS_THREADS */
00126 
00127 #endif /* !APR_ANYLOCK_H */

Generated on Fri Apr 23 07:22:21 2004 for Apache Portable Runtime Utility Library by doxygen 1.3.4