00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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
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
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
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
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
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
00127
00128 #endif