00001 /* Licensed to the Apache Software Foundation (ASF) under one or more 00002 * contributor license agreements. See the NOTICE file distributed with 00003 * this work for additional information regarding copyright ownership. 00004 * The ASF licenses this file to You under the Apache License, Version 2.0 00005 * (the "License"); you may not use this file except in compliance with 00006 * the License. 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_MUTEX_H 00018 #define APR_THREAD_MUTEX_H 00019 00020 /** 00021 * @file apr_thread_mutex.h 00022 * @brief APR Thread Mutex Routines 00023 */ 00024 00025 #include "apr.h" 00026 #include "apr_errno.h" 00027 00028 #ifdef __cplusplus 00029 extern "C" { 00030 #endif /* __cplusplus */ 00031 00032 #if APR_HAS_THREADS || defined(DOXYGEN) 00033 00034 /** 00035 * @defgroup apr_thread_mutex Thread Mutex Routines 00036 * @ingroup APR 00037 * @{ 00038 */ 00039 00040 /** Opaque thread-local mutex structure */ 00041 typedef struct apr_thread_mutex_t apr_thread_mutex_t; 00042 00043 #define APR_THREAD_MUTEX_DEFAULT 0x0 /**< platform-optimal lock behavior */ 00044 #define APR_THREAD_MUTEX_NESTED 0x1 /**< enable nested (recursive) locks */ 00045 #define APR_THREAD_MUTEX_UNNESTED 0x2 /**< disable nested locks */ 00046 #define APR_THREAD_MUTEX_TIMED 0x4 /**< enable timed locks */ 00047 00048 /* Delayed the include to avoid a circular reference */ 00049 #include "apr_pools.h" 00050 #include "apr_time.h" 00051 00052 /** 00053 * Create and initialize a mutex that can be used to synchronize threads. 00054 * @param mutex the memory address where the newly created mutex will be 00055 * stored. 00056 * @param flags Or'ed value of: 00057 * <PRE> 00058 * APR_THREAD_MUTEX_DEFAULT platform-optimal lock behavior. 00059 * APR_THREAD_MUTEX_NESTED enable nested (recursive) locks. 00060 * APR_THREAD_MUTEX_UNNESTED disable nested locks (non-recursive). 00061 * </PRE> 00062 * @param pool the pool from which to allocate the mutex. 00063 * @warning Be cautious in using APR_THREAD_MUTEX_DEFAULT. While this is the 00064 * most optimal mutex based on a given platform's performance characteristics, 00065 * it will behave as either a nested or an unnested lock. 00066 */ 00067 APR_DECLARE(apr_status_t) apr_thread_mutex_create(apr_thread_mutex_t **mutex, 00068 unsigned int flags, 00069 apr_pool_t *pool); 00070 /** 00071 * Acquire the lock for the given mutex. If the mutex is already locked, 00072 * the current thread will be put to sleep until the lock becomes available. 00073 * @param mutex the mutex on which to acquire the lock. 00074 */ 00075 APR_DECLARE(apr_status_t) apr_thread_mutex_lock(apr_thread_mutex_t *mutex); 00076 00077 /** 00078 * Attempt to acquire the lock for the given mutex. If the mutex has already 00079 * been acquired, the call returns immediately with APR_EBUSY. Note: it 00080 * is important that the APR_STATUS_IS_EBUSY(s) macro be used to determine 00081 * if the return value was APR_EBUSY, for portability reasons. 00082 * @param mutex the mutex on which to attempt the lock acquiring. 00083 */ 00084 APR_DECLARE(apr_status_t) apr_thread_mutex_trylock(apr_thread_mutex_t *mutex); 00085 00086 /** 00087 * Attempt to acquire the lock for the given mutex until timeout expires. 00088 * If the acquisition time outs, the call returns with APR_TIMEUP. 00089 * @param mutex the mutex on which to attempt the lock acquiring. 00090 * @param timeout the relative timeout (microseconds). 00091 * @note A timeout negative or nul means immediate attempt, returning 00092 * APR_TIMEUP without blocking if it the lock is already acquired. 00093 */ 00094 APR_DECLARE(apr_status_t) apr_thread_mutex_timedlock(apr_thread_mutex_t *mutex, 00095 apr_interval_time_t timeout); 00096 00097 /** 00098 * Release the lock for the given mutex. 00099 * @param mutex the mutex from which to release the lock. 00100 */ 00101 APR_DECLARE(apr_status_t) apr_thread_mutex_unlock(apr_thread_mutex_t *mutex); 00102 00103 /** 00104 * Destroy the mutex and free the memory associated with the lock. 00105 * @param mutex the mutex to destroy. 00106 */ 00107 APR_DECLARE(apr_status_t) apr_thread_mutex_destroy(apr_thread_mutex_t *mutex); 00108 00109 /** 00110 * Get the pool used by this thread_mutex. 00111 * @return apr_pool_t the pool 00112 */ 00113 APR_POOL_DECLARE_ACCESSOR(thread_mutex); 00114 00115 #endif /* APR_HAS_THREADS */ 00116 00117 /** @} */ 00118 00119 #ifdef __cplusplus 00120 } 00121 #endif 00122 00123 #endif /* ! APR_THREAD_MUTEX_H */
1.5.6