include/apr_anylock.h

Go to the documentation of this file.
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 
00021 #ifndef APR_ANYLOCK_H
00022 #define APR_ANYLOCK_H
00023 
00024 #include "apr_proc_mutex.h"
00025 #include "apr_thread_mutex.h"
00026 #include "apr_thread_rwlock.h"
00027 
00029 typedef struct apr_anylock_t {
00031     enum tm_lock {
00032         apr_anylock_none,           
00033         apr_anylock_procmutex,      
00034         apr_anylock_threadmutex,    
00035         apr_anylock_readlock,       
00036         apr_anylock_writelock       
00037     } type;
00039     union apr_anylock_u_t {
00040         apr_proc_mutex_t *pm;       
00041 #if APR_HAS_THREADS
00042         apr_thread_mutex_t *tm;     
00043         apr_thread_rwlock_t *rw;    
00044 #endif
00045     } lock;
00046 } apr_anylock_t;
00047 
00048 #if APR_HAS_THREADS
00049 
00051 #define APR_ANYLOCK_LOCK(lck)                \
00052     (((lck)->type == apr_anylock_none)         \
00053       ? APR_SUCCESS                              \
00054       : (((lck)->type == apr_anylock_threadmutex)  \
00055           ? apr_thread_mutex_lock((lck)->lock.tm)    \
00056           : (((lck)->type == apr_anylock_procmutex)    \
00057               ? apr_proc_mutex_lock((lck)->lock.pm)      \
00058               : (((lck)->type == apr_anylock_readlock)     \
00059                   ? apr_thread_rwlock_rdlock((lck)->lock.rw) \
00060                   : (((lck)->type == apr_anylock_writelock)    \
00061                       ? apr_thread_rwlock_wrlock((lck)->lock.rw) \
00062                       : APR_EINVAL)))))
00063 
00064 #else /* APR_HAS_THREADS */
00065 
00066 #define APR_ANYLOCK_LOCK(lck)                \
00067     (((lck)->type == apr_anylock_none)         \
00068       ? APR_SUCCESS                              \
00069           : (((lck)->type == apr_anylock_procmutex)    \
00070               ? apr_proc_mutex_lock((lck)->lock.pm)      \
00071                       : APR_EINVAL))
00072 
00073 #endif /* APR_HAS_THREADS */
00074 
00075 #if APR_HAS_THREADS
00076 
00078 #define APR_ANYLOCK_TRYLOCK(lck)                \
00079     (((lck)->type == apr_anylock_none)            \
00080       ? APR_SUCCESS                                 \
00081       : (((lck)->type == apr_anylock_threadmutex)     \
00082           ? apr_thread_mutex_trylock((lck)->lock.tm)    \
00083           : (((lck)->type == apr_anylock_procmutex)       \
00084               ? apr_proc_mutex_trylock((lck)->lock.pm)      \
00085               : (((lck)->type == apr_anylock_readlock)        \
00086                   ? apr_thread_rwlock_tryrdlock((lck)->lock.rw) \
00087                   : (((lck)->type == apr_anylock_writelock)       \
00088                       ? apr_thread_rwlock_trywrlock((lck)->lock.rw) \
00089                           : APR_EINVAL)))))
00090 
00091 #else /* APR_HAS_THREADS */
00092 
00093 #define APR_ANYLOCK_TRYLOCK(lck)                \
00094     (((lck)->type == apr_anylock_none)            \
00095       ? APR_SUCCESS                                 \
00096           : (((lck)->type == apr_anylock_procmutex)       \
00097               ? apr_proc_mutex_trylock((lck)->lock.pm)      \
00098                           : APR_EINVAL))
00099 
00100 #endif /* APR_HAS_THREADS */
00101 
00102 #if APR_HAS_THREADS
00103 
00105 #define APR_ANYLOCK_UNLOCK(lck)              \
00106     (((lck)->type == apr_anylock_none)         \
00107       ? APR_SUCCESS                              \
00108       : (((lck)->type == apr_anylock_threadmutex)  \
00109           ? apr_thread_mutex_unlock((lck)->lock.tm)  \
00110           : (((lck)->type == apr_anylock_procmutex)    \
00111               ? apr_proc_mutex_unlock((lck)->lock.pm)    \
00112               : ((((lck)->type == apr_anylock_readlock) || \
00113                   ((lck)->type == apr_anylock_writelock))    \
00114                   ? apr_thread_rwlock_unlock((lck)->lock.rw)   \
00115                       : APR_EINVAL))))
00116 
00117 #else /* APR_HAS_THREADS */
00118 
00119 #define APR_ANYLOCK_UNLOCK(lck)              \
00120     (((lck)->type == apr_anylock_none)         \
00121       ? APR_SUCCESS                              \
00122           : (((lck)->type == apr_anylock_procmutex)    \
00123               ? apr_proc_mutex_unlock((lck)->lock.pm)    \
00124                       : APR_EINVAL))
00125 
00126 #endif /* APR_HAS_THREADS */
00127 
00128 #endif /* !APR_ANYLOCK_H */

Generated on Tue Sep 11 08:13:14 2007 for Apache Portable Runtime Utility Library by  doxygen 1.5.2