<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> <title>Apache Portable Runtime: apr_global_mutex.h Source File</title> <link href="doxygen.css" rel="stylesheet" type="text/css"> </head><body> <!-- Generated by Doxygen 1.3.9.1 --> <div class="qindex"><a class="qindex" href="index.html">Main Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="annotated.html">Data Structures</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="functions.html">Data Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related Pages</a></div> <div class="nav"> <a class="el" href="dir_000000.html">home</a> / <a class="el" href="dir_000001.html">oden</a> / <a class="el" href="dir_000002.html">RPM</a> / <a class="el" href="dir_000003.html">BUILD</a> / <a class="el" href="dir_000004.html">apr-1.1.1</a> / <a class="el" href="dir_000005.html">include</a></div> <h1>apr_global_mutex.h</h1><a href="apr__global__mutex_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="comment">/* Copyright 2000-2004 The Apache Software Foundation</span> 00002 <span class="comment"> *</span> 00003 <span class="comment"> * Licensed under the Apache License, Version 2.0 (the "License");</span> 00004 <span class="comment"> * you may not use this file except in compliance with the License.</span> 00005 <span class="comment"> * You may obtain a copy of the License at</span> 00006 <span class="comment"> *</span> 00007 <span class="comment"> * http://www.apache.org/licenses/LICENSE-2.0</span> 00008 <span class="comment"> *</span> 00009 <span class="comment"> * Unless required by applicable law or agreed to in writing, software</span> 00010 <span class="comment"> * distributed under the License is distributed on an "AS IS" BASIS,</span> 00011 <span class="comment"> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span> 00012 <span class="comment"> * See the License for the specific language governing permissions and</span> 00013 <span class="comment"> * limitations under the License.</span> 00014 <span class="comment"> */</span> 00015 00016 <span class="preprocessor">#ifndef APR_GLOBAL_MUTEX_H</span> 00017 <span class="preprocessor"></span><span class="preprocessor">#define APR_GLOBAL_MUTEX_H</span> 00018 <span class="preprocessor"></span><span class="comment"></span> 00019 <span class="comment">/**</span> 00020 <span class="comment"> * @file apr_global_mutex.h</span> 00021 <span class="comment"> * @brief APR Global Locking Routines</span> 00022 <span class="comment"> */</span> 00023 00024 <span class="preprocessor">#include "<a class="code" href="apr_8h.html">apr.h</a>"</span> 00025 <span class="preprocessor">#include "<a class="code" href="apr__proc__mutex_8h.html">apr_proc_mutex.h</a>"</span> <span class="comment">/* only for apr_lockmech_e */</span> 00026 <span class="preprocessor">#include "<a class="code" href="apr__pools_8h.html">apr_pools.h</a>"</span> 00027 <span class="preprocessor">#include "<a class="code" href="apr__errno_8h.html">apr_errno.h</a>"</span> 00028 <span class="preprocessor">#if APR_PROC_MUTEX_IS_GLOBAL</span> 00029 <span class="preprocessor"></span><span class="preprocessor">#include "<a class="code" href="apr__proc__mutex_8h.html">apr_proc_mutex.h</a>"</span> 00030 <span class="preprocessor">#endif</span> 00031 <span class="preprocessor"></span> 00032 <span class="preprocessor">#ifdef __cplusplus</span> 00033 <span class="preprocessor"></span><span class="keyword">extern</span> <span class="stringliteral">"C"</span> { 00034 <span class="preprocessor">#endif </span><span class="comment">/* __cplusplus */</span> 00035 <span class="comment"></span> 00036 <span class="comment">/**</span> 00037 <span class="comment"> * @defgroup APR_GlobalMutex Global Locking Routines</span> 00038 <span class="comment"> * @ingroup APR </span> 00039 <span class="comment"> * @{</span> 00040 <span class="comment"> */</span> 00041 00042 <span class="preprocessor">#if !APR_PROC_MUTEX_IS_GLOBAL || defined(DOXYGEN)</span> 00043 <span class="preprocessor"></span><span class="comment"></span> 00044 <span class="comment">/** Opaque global mutex structure. */</span> <a name="l00045"></a><a class="code" href="group__APR__GlobalMutex.html#ga0">00045</a> <span class="keyword">typedef</span> <span class="keyword">struct </span><a class="code" href="group__APR__GlobalMutex.html#ga0">apr_global_mutex_t</a> <a class="code" href="group__APR__GlobalMutex.html#ga0">apr_global_mutex_t</a>; 00046 00047 <span class="comment">/* Function definitions */</span> 00048 <span class="comment"></span> 00049 <span class="comment">/**</span> 00050 <span class="comment"> * Create and initialize a mutex that can be used to synchronize both</span> 00051 <span class="comment"> * processes and threads. Note: There is considerable overhead in using</span> 00052 <span class="comment"> * this API if only cross-process or cross-thread mutual exclusion is</span> 00053 <span class="comment"> * required. See apr_proc_mutex.h and apr_thread_mutex.h for more</span> 00054 <span class="comment"> * specialized lock routines.</span> 00055 <span class="comment"> * @param mutex the memory address where the newly created mutex will be</span> 00056 <span class="comment"> * stored.</span> 00057 <span class="comment"> * @param fname A file name to use if the lock mechanism requires one. This</span> 00058 <span class="comment"> * argument should always be provided. The lock code itself will</span> 00059 <span class="comment"> * determine if it should be used.</span> 00060 <span class="comment"> * @param mech The mechanism to use for the interprocess lock, if any; one of</span> 00061 <span class="comment"> * <PRE></span> 00062 <span class="comment"> * APR_LOCK_FCNTL</span> 00063 <span class="comment"> * APR_LOCK_FLOCK</span> 00064 <span class="comment"> * APR_LOCK_SYSVSEM</span> 00065 <span class="comment"> * APR_LOCK_POSIXSEM</span> 00066 <span class="comment"> * APR_LOCK_PROC_PTHREAD</span> 00067 <span class="comment"> * APR_LOCK_DEFAULT pick the default mechanism for the platform</span> 00068 <span class="comment"> * </PRE></span> 00069 <span class="comment"> * @param pool the pool from which to allocate the mutex.</span> 00070 <span class="comment"> * @warning Check APR_HAS_foo_SERIALIZE defines to see if the platform supports</span> 00071 <span class="comment"> * APR_LOCK_foo. Only APR_LOCK_DEFAULT is portable.</span> 00072 <span class="comment"> */</span> 00073 <a class="code" href="group__apr__platform.html#ga123">APR_DECLARE</a>(apr_status_t) apr_global_mutex_create(apr_global_mutex_t **mutex, 00074 const <span class="keywordtype">char</span> *fname, 00075 apr_lockmech_e mech, 00076 apr_pool_t *pool); 00077 <span class="comment"></span> 00078 <span class="comment">/**</span> 00079 <span class="comment"> * Re-open a mutex in a child process.</span> 00080 <span class="comment"> * @param mutex The newly re-opened mutex structure.</span> 00081 <span class="comment"> * @param fname A file name to use if the mutex mechanism requires one. This</span> 00082 <span class="comment"> * argument should always be provided. The mutex code itself will</span> 00083 <span class="comment"> * determine if it should be used. This filename should be the </span> 00084 <span class="comment"> * same one that was passed to apr_global_mutex_create().</span> 00085 <span class="comment"> * @param pool The pool to operate on.</span> 00086 <span class="comment"> * @remark This function must be called to maintain portability, even</span> 00087 <span class="comment"> * if the underlying lock mechanism does not require it.</span> 00088 <span class="comment"> */</span> 00089 APR_DECLARE(apr_status_t) apr_global_mutex_child_init( 00090 apr_global_mutex_t **mutex, 00091 const <span class="keywordtype">char</span> *fname, 00092 apr_pool_t *pool); 00093 <span class="comment"></span> 00094 <span class="comment">/**</span> 00095 <span class="comment"> * Acquire the lock for the given mutex. If the mutex is already locked,</span> 00096 <span class="comment"> * the current thread will be put to sleep until the lock becomes available.</span> 00097 <span class="comment"> * @param mutex the mutex on which to acquire the lock.</span> 00098 <span class="comment"> */</span> 00099 APR_DECLARE(apr_status_t) apr_global_mutex_lock(apr_global_mutex_t *mutex); 00100 <span class="comment"></span> 00101 <span class="comment">/**</span> 00102 <span class="comment"> * Attempt to acquire the lock for the given mutex. If the mutex has already</span> 00103 <span class="comment"> * been acquired, the call returns immediately with APR_EBUSY. Note: it</span> 00104 <span class="comment"> * is important that the APR_STATUS_IS_EBUSY(s) macro be used to determine</span> 00105 <span class="comment"> * if the return value was APR_EBUSY, for portability reasons.</span> 00106 <span class="comment"> * @param mutex the mutex on which to attempt the lock acquiring.</span> 00107 <span class="comment"> */</span> 00108 APR_DECLARE(apr_status_t) apr_global_mutex_trylock(apr_global_mutex_t *mutex); 00109 <span class="comment"></span> 00110 <span class="comment">/**</span> 00111 <span class="comment"> * Release the lock for the given mutex.</span> 00112 <span class="comment"> * @param mutex the mutex from which to release the lock.</span> 00113 <span class="comment"> */</span> 00114 APR_DECLARE(apr_status_t) apr_global_mutex_unlock(apr_global_mutex_t *mutex); 00115 <span class="comment"></span> 00116 <span class="comment">/**</span> 00117 <span class="comment"> * Destroy the mutex and free the memory associated with the lock.</span> 00118 <span class="comment"> * @param mutex the mutex to destroy.</span> 00119 <span class="comment"> */</span> 00120 APR_DECLARE(apr_status_t) apr_global_mutex_destroy(apr_global_mutex_t *mutex); 00121 <span class="comment"></span> 00122 <span class="comment">/**</span> 00123 <span class="comment"> * Get the pool used by this global_mutex.</span> 00124 <span class="comment"> * @return apr_pool_t the pool</span> 00125 <span class="comment"> */</span> 00126 APR_POOL_DECLARE_ACCESSOR(global_mutex); 00127 00128 #else <span class="comment">/* APR_PROC_MUTEX_IS_GLOBAL */</span> 00129 00130 <span class="comment">/* Some platforms [e.g. Win32] have cross process locks that are truly</span> 00131 <span class="comment"> * global locks, since there isn't the concept of cross-process locks.</span> 00132 <span class="comment"> * Define these platforms in terms of an apr_proc_mutex_t.</span> 00133 <span class="comment"> */</span> 00134 00135 #define apr_global_mutex_t apr_proc_mutex_t 00136 #define apr_global_mutex_create apr_proc_mutex_create 00137 #define apr_global_mutex_child_init apr_proc_mutex_child_init 00138 #define apr_global_mutex_lock apr_proc_mutex_lock 00139 #define apr_global_mutex_trylock apr_proc_mutex_trylock 00140 #define apr_global_mutex_unlock apr_proc_mutex_unlock 00141 #define apr_global_mutex_destroy apr_proc_mutex_destroy 00142 #define apr_global_mutex_pool_get apr_proc_mutex_pool_get 00143 00144 #endif 00145 <span class="comment"></span> 00146 <span class="comment">/** @} */</span> 00147 00148 #ifdef __cplusplus 00149 } 00150 #endif 00151 00152 #endif <span class="comment">/* ndef APR_GLOBAL_MUTEX_H */</span> </pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Mar 20 19:52:26 2005 for Apache Portable Runtime by <a href="http://www.doxygen.org/index.html"> <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.3.9.1 </small></address> </body> </html>