apr_global_mutex.h

説明を見る。
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_GLOBAL_MUTEX_H
00018 #define APR_GLOBAL_MUTEX_H
00019 
00020 /**
00021  * @file apr_global_mutex.h
00022  * @brief APR Global Locking Routines
00023  */
00024 
00025 #include "apr.h"
00026 #include "apr_proc_mutex.h"    /* only for apr_lockmech_e */
00027 #include "apr_pools.h"
00028 #include "apr_errno.h"
00029 #if APR_PROC_MUTEX_IS_GLOBAL
00030 #include "apr_proc_mutex.h"
00031 #endif
00032 
00033 #ifdef __cplusplus
00034 extern "C" {
00035 #endif /* __cplusplus */
00036 
00037 /**
00038  * @defgroup APR_GlobalMutex Global Locking Routines
00039  * @ingroup APR 
00040  * @{
00041  */
00042 
00043 #if !APR_PROC_MUTEX_IS_GLOBAL || defined(DOXYGEN)
00044 
00045 /** Opaque global mutex structure. */
00046 typedef struct apr_global_mutex_t apr_global_mutex_t;
00047 
00048 /*   Function definitions */
00049 
00050 /**
00051  * Create and initialize a mutex that can be used to synchronize both
00052  * processes and threads. Note: There is considerable overhead in using
00053  * this API if only cross-process or cross-thread mutual exclusion is
00054  * required. See apr_proc_mutex.h and apr_thread_mutex.h for more
00055  * specialized lock routines.
00056  * @param mutex the memory address where the newly created mutex will be
00057  *        stored.
00058  * @param fname A file name to use if the lock mechanism requires one.  This
00059  *        argument should always be provided.  The lock code itself will
00060  *        determine if it should be used.
00061  * @param mech The mechanism to use for the interprocess lock, if any; one of
00062  * <PRE>
00063  *            APR_LOCK_FCNTL
00064  *            APR_LOCK_FLOCK
00065  *            APR_LOCK_SYSVSEM
00066  *            APR_LOCK_POSIXSEM
00067  *            APR_LOCK_PROC_PTHREAD
00068  *            APR_LOCK_DEFAULT     pick the default mechanism for the platform
00069  * </PRE>
00070  * @param pool the pool from which to allocate the mutex.
00071  * @warning Check APR_HAS_foo_SERIALIZE defines to see if the platform supports
00072  *          APR_LOCK_foo.  Only APR_LOCK_DEFAULT is portable.
00073  */
00074 APR_DECLARE(apr_status_t) apr_global_mutex_create(apr_global_mutex_t **mutex,
00075                                                   const char *fname,
00076                                                   apr_lockmech_e mech,
00077                                                   apr_pool_t *pool);
00078 
00079 /**
00080  * Re-open a mutex in a child process.
00081  * @param mutex The newly re-opened mutex structure.
00082  * @param fname A file name to use if the mutex mechanism requires one.  This
00083  *              argument should always be provided.  The mutex code itself will
00084  *              determine if it should be used.  This filename should be the 
00085  *              same one that was passed to apr_global_mutex_create().
00086  * @param pool The pool to operate on.
00087  * @remark This function must be called to maintain portability, even
00088  *         if the underlying lock mechanism does not require it.
00089  */
00090 APR_DECLARE(apr_status_t) apr_global_mutex_child_init(
00091                               apr_global_mutex_t **mutex,
00092                               const char *fname,
00093                               apr_pool_t *pool);
00094 
00095 /**
00096  * Acquire the lock for the given mutex. If the mutex is already locked,
00097  * the current thread will be put to sleep until the lock becomes available.
00098  * @param mutex the mutex on which to acquire the lock.
00099  */
00100 APR_DECLARE(apr_status_t) apr_global_mutex_lock(apr_global_mutex_t *mutex);
00101 
00102 /**
00103  * Attempt to acquire the lock for the given mutex. If the mutex has already
00104  * been acquired, the call returns immediately with APR_EBUSY. Note: it
00105  * is important that the APR_STATUS_IS_EBUSY(s) macro be used to determine
00106  * if the return value was APR_EBUSY, for portability reasons.
00107  * @param mutex the mutex on which to attempt the lock acquiring.
00108  */
00109 APR_DECLARE(apr_status_t) apr_global_mutex_trylock(apr_global_mutex_t *mutex);
00110 
00111 /**
00112  * Release the lock for the given mutex.
00113  * @param mutex the mutex from which to release the lock.
00114  */
00115 APR_DECLARE(apr_status_t) apr_global_mutex_unlock(apr_global_mutex_t *mutex);
00116 
00117 /**
00118  * Destroy the mutex and free the memory associated with the lock.
00119  * @param mutex the mutex to destroy.
00120  */
00121 APR_DECLARE(apr_status_t) apr_global_mutex_destroy(apr_global_mutex_t *mutex);
00122 
00123 /**
00124  * Get the pool used by this global_mutex.
00125  * @return apr_pool_t the pool
00126  */
00127 APR_POOL_DECLARE_ACCESSOR(global_mutex);
00128 
00129 #else /* APR_PROC_MUTEX_IS_GLOBAL */
00130 
00131 /* Some platforms [e.g. Win32] have cross process locks that are truly
00132  * global locks, since there isn't the concept of cross-process locks.
00133  * Define these platforms in terms of an apr_proc_mutex_t.
00134  */
00135 
00136 #define apr_global_mutex_t          apr_proc_mutex_t
00137 #define apr_global_mutex_create     apr_proc_mutex_create
00138 #define apr_global_mutex_child_init apr_proc_mutex_child_init
00139 #define apr_global_mutex_lock       apr_proc_mutex_lock
00140 #define apr_global_mutex_trylock    apr_proc_mutex_trylock
00141 #define apr_global_mutex_unlock     apr_proc_mutex_unlock
00142 #define apr_global_mutex_destroy    apr_proc_mutex_destroy
00143 #define apr_global_mutex_pool_get   apr_proc_mutex_pool_get
00144 
00145 #endif
00146 
00147 /** @} */
00148 
00149 #ifdef __cplusplus
00150 }
00151 #endif
00152 
00153 #endif  /* ndef APR_GLOBAL_MUTEX_H */

Apache Portable Runtimeに対してSun Jul 19 22:04:00 2009に生成されました。  doxygen 1.4.7