Sophie

Sophie

distrib > Mandriva > 10.2 > i586 > media > contrib > by-pkgid > 4f37b923758ceff94a2c0ccca62b4b43 > files > 98

libapr1-devel-1.1.1-1mdk.i586.rpm

<!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_ring.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&nbsp;Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="annotated.html">Data&nbsp;Structures</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Data&nbsp;Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related&nbsp;Pages</a></div>
<div class="nav">
<a class="el" href="dir_000000.html">home</a>&nbsp;/&nbsp;<a class="el" href="dir_000001.html">oden</a>&nbsp;/&nbsp;<a class="el" href="dir_000002.html">RPM</a>&nbsp;/&nbsp;<a class="el" href="dir_000003.html">BUILD</a>&nbsp;/&nbsp;<a class="el" href="dir_000004.html">apr-1.1.1</a>&nbsp;/&nbsp;<a class="el" href="dir_000005.html">include</a></div>
<h1>apr_ring.h</h1><a href="apr__ring_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="comment">/*</span>
00017 <span class="comment"> * This code draws heavily from the 4.4BSD &lt;sys/queue.h&gt; macros</span>
00018 <span class="comment"> * and Dean Gaudet's "splim/ring.h".</span>
00019 <span class="comment"> * &lt;http://www.freebsd.org/cgi/cvsweb.cgi/src/sys/sys/queue.h&gt;</span>
00020 <span class="comment"> * &lt;http://www.arctic.org/~dean/splim/&gt;</span>
00021 <span class="comment"> *</span>
00022 <span class="comment"> * We'd use Dean's code directly if we could guarantee the</span>
00023 <span class="comment"> * availability of inline functions.</span>
00024 <span class="comment"> */</span>
00025 
00026 <span class="preprocessor">#ifndef APR_RING_H</span>
00027 <span class="preprocessor"></span><span class="preprocessor">#define APR_RING_H</span>
00028 <span class="preprocessor"></span><span class="comment"></span>
00029 <span class="comment">/**</span>
00030 <span class="comment"> * @file apr_ring.h</span>
00031 <span class="comment"> * @brief APR Rings</span>
00032 <span class="comment"> */</span>
00033 
00034 <span class="comment">/*</span>
00035 <span class="comment"> * for offsetof()</span>
00036 <span class="comment"> */</span>
00037 <span class="preprocessor">#include "<a class="code" href="apr__general_8h.html">apr_general.h</a>"</span>
00038 <span class="comment"></span>
00039 <span class="comment">/**</span>
00040 <span class="comment"> * @defgroup apr_ring Ring Macro Implementations</span>
00041 <span class="comment"> * @ingroup APR </span>
00042 <span class="comment"> * A ring is a kind of doubly-linked list that can be manipulated</span>
00043 <span class="comment"> * without knowing where its head is.</span>
00044 <span class="comment"> * @{</span>
00045 <span class="comment"> */</span>
00046 <span class="comment"></span>
00047 <span class="comment">/**</span>
00048 <span class="comment"> * The Ring Element</span>
00049 <span class="comment"> *</span>
00050 <span class="comment"> * A ring element struct is linked to the other elements in the ring</span>
00051 <span class="comment"> * through its ring entry field, e.g.</span>
00052 <span class="comment"> * &lt;pre&gt;</span>
00053 <span class="comment"> *      struct my_element_t {</span>
00054 <span class="comment"> *          APR_RING_ENTRY(my_element_t) link;</span>
00055 <span class="comment"> *          int foo;</span>
00056 <span class="comment"> *          char *bar;</span>
00057 <span class="comment"> *      };</span>
00058 <span class="comment"> * &lt;/pre&gt;</span>
00059 <span class="comment"> *</span>
00060 <span class="comment"> * An element struct may be put on more than one ring if it has more</span>
00061 <span class="comment"> * than one APR_RING_ENTRY field. Each APR_RING_ENTRY has a corresponding</span>
00062 <span class="comment"> * APR_RING_HEAD declaration.</span>
00063 <span class="comment"> *</span>
00064 <span class="comment"> * @warning For strict C standards compliance you should put the APR_RING_ENTRY</span>
00065 <span class="comment"> * first in the element struct unless the head is always part of a larger</span>
00066 <span class="comment"> * object with enough earlier fields to accommodate the offsetof() used</span>
00067 <span class="comment"> * to compute the ring sentinel below. You can usually ignore this caveat.</span>
00068 <span class="comment"> */</span>
<a name="l00069"></a><a class="code" href="group__apr__ring.html#ga0">00069</a> <span class="preprocessor">#define APR_RING_ENTRY(elem)                                            \</span>
00070 <span class="preprocessor">    struct {                                                            \</span>
00071 <span class="preprocessor">        struct elem *next;                                              \</span>
00072 <span class="preprocessor">        struct elem *prev;                                              \</span>
00073 <span class="preprocessor">    }</span>
00074 <span class="preprocessor"></span><span class="comment"></span>
00075 <span class="comment">/**</span>
00076 <span class="comment"> * The Ring Head</span>
00077 <span class="comment"> *</span>
00078 <span class="comment"> * Each ring is managed via its head, which is a struct declared like this:</span>
00079 <span class="comment"> * &lt;pre&gt;</span>
00080 <span class="comment"> *      APR_RING_HEAD(my_ring_t, my_element_t);</span>
00081 <span class="comment"> *      struct my_ring_t ring, *ringp;</span>
00082 <span class="comment"> * &lt;/pre&gt;</span>
00083 <span class="comment"> *</span>
00084 <span class="comment"> * This struct looks just like the element link struct so that we can</span>
00085 <span class="comment"> * be sure that the typecasting games will work as expected.</span>
00086 <span class="comment"> *</span>
00087 <span class="comment"> * The first element in the ring is next after the head, and the last</span>
00088 <span class="comment"> * element is just before the head.</span>
00089 <span class="comment"> */</span>
<a name="l00090"></a><a class="code" href="group__apr__ring.html#ga1">00090</a> <span class="preprocessor">#define APR_RING_HEAD(head, elem)                                       \</span>
00091 <span class="preprocessor">    struct head {                                                       \</span>
00092 <span class="preprocessor">        struct elem *next;                                              \</span>
00093 <span class="preprocessor">        struct elem *prev;                                              \</span>
00094 <span class="preprocessor">    }</span>
00095 <span class="preprocessor"></span><span class="comment"></span>
00096 <span class="comment">/**</span>
00097 <span class="comment"> * The Ring Sentinel</span>
00098 <span class="comment"> *</span>
00099 <span class="comment"> * This is the magic pointer value that occurs before the first and</span>
00100 <span class="comment"> * after the last elements in the ring, computed from the address of</span>
00101 <span class="comment"> * the ring's head.  The head itself isn't an element, but in order to</span>
00102 <span class="comment"> * get rid of all the special cases when dealing with the ends of the</span>
00103 <span class="comment"> * ring, we play typecasting games to make it look like one.</span>
00104 <span class="comment"> *</span>
00105 <span class="comment"> * Here is a diagram to illustrate the arrangements of the next and</span>
00106 <span class="comment"> * prev pointers of each element in a single ring. Note that they point</span>
00107 <span class="comment"> * to the start of each element, not to the APR_RING_ENTRY structure.</span>
00108 <span class="comment"> *</span>
00109 <span class="comment"> * &lt;pre&gt;</span>
00110 <span class="comment"> *     +-&gt;+------+&lt;-+  +-&gt;+------+&lt;-+  +-&gt;+------+&lt;-+</span>
00111 <span class="comment"> *     |  |struct|  |  |  |struct|  |  |  |struct|  |</span>
00112 <span class="comment"> *    /   | elem |   \/   | elem |   \/   | elem |  \</span>
00113 <span class="comment"> * ...    |      |   /\   |      |   /\   |      |   ...</span>
00114 <span class="comment"> *        +------+  |  |  +------+  |  |  +------+</span>
00115 <span class="comment"> *   ...--|prev  |  |  +--|ring  |  |  +--|prev  |</span>
00116 <span class="comment"> *        |  next|--+     | entry|--+     |  next|--...</span>
00117 <span class="comment"> *        +------+        +------+        +------+</span>
00118 <span class="comment"> *        | etc. |        | etc. |        | etc. |</span>
00119 <span class="comment"> *        :      :        :      :        :      :</span>
00120 <span class="comment"> * &lt;/pre&gt;</span>
00121 <span class="comment"> *</span>
00122 <span class="comment"> * The APR_RING_HEAD is nothing but a bare APR_RING_ENTRY. The prev</span>
00123 <span class="comment"> * and next pointers in the first and last elements don't actually</span>
00124 <span class="comment"> * point to the head, they point to a phantom place called the</span>
00125 <span class="comment"> * sentinel. Its value is such that last-&gt;next-&gt;next == first because</span>
00126 <span class="comment"> * the offset from the sentinel to the head's next pointer is the same</span>
00127 <span class="comment"> * as the offset from the start of an element to its next pointer.</span>
00128 <span class="comment"> * This also works in the opposite direction.</span>
00129 <span class="comment"> *</span>
00130 <span class="comment"> * &lt;pre&gt;</span>
00131 <span class="comment"> *        last                            first</span>
00132 <span class="comment"> *     +-&gt;+------+&lt;-+  +-&gt;sentinel&lt;-+  +-&gt;+------+&lt;-+</span>
00133 <span class="comment"> *     |  |struct|  |  |            |  |  |struct|  |</span>
00134 <span class="comment"> *    /   | elem |   \/              \/   | elem |  \</span>
00135 <span class="comment"> * ...    |      |   /\              /\   |      |   ...</span>
00136 <span class="comment"> *        +------+  |  |  +------+  |  |  +------+</span>
00137 <span class="comment"> *   ...--|prev  |  |  +--|ring  |  |  +--|prev  |</span>
00138 <span class="comment"> *        |  next|--+     |  head|--+     |  next|--...</span>
00139 <span class="comment"> *        +------+        +------+        +------+</span>
00140 <span class="comment"> *        | etc. |                        | etc. |</span>
00141 <span class="comment"> *        :      :                        :      :</span>
00142 <span class="comment"> * &lt;/pre&gt;</span>
00143 <span class="comment"> *</span>
00144 <span class="comment"> * Note that the offset mentioned above is different for each kind of</span>
00145 <span class="comment"> * ring that the element may be on, and each kind of ring has a unique</span>
00146 <span class="comment"> * name for its APR_RING_ENTRY in each element, and has its own type</span>
00147 <span class="comment"> * for its APR_RING_HEAD.</span>
00148 <span class="comment"> *</span>
00149 <span class="comment"> * Note also that if the offset is non-zero (which is required if an</span>
00150 <span class="comment"> * element has more than one APR_RING_ENTRY), the unreality of the</span>
00151 <span class="comment"> * sentinel may have bad implications on very perverse implementations</span>
00152 <span class="comment"> * of C -- see the warning in APR_RING_ENTRY.</span>
00153 <span class="comment"> *</span>
00154 <span class="comment"> * @param hp   The head of the ring</span>
00155 <span class="comment"> * @param elem The name of the element struct</span>
00156 <span class="comment"> * @param link The name of the APR_RING_ENTRY in the element struct</span>
00157 <span class="comment"> */</span>
<a name="l00158"></a><a class="code" href="group__apr__ring.html#ga2">00158</a> <span class="preprocessor">#define APR_RING_SENTINEL(hp, elem, link)                               \</span>
00159 <span class="preprocessor">    (struct elem *)((char *)(hp) - APR_OFFSETOF(struct elem, link))</span>
00160 <span class="preprocessor"></span><span class="comment"></span>
00161 <span class="comment">/**</span>
00162 <span class="comment"> * The first element of the ring</span>
00163 <span class="comment"> * @param hp   The head of the ring</span>
00164 <span class="comment"> */</span>
<a name="l00165"></a><a class="code" href="group__apr__ring.html#ga3">00165</a> <span class="preprocessor">#define APR_RING_FIRST(hp)      (hp)-&gt;next</span>
00166 <span class="preprocessor"></span><span class="comment">/**</span>
00167 <span class="comment"> * The last element of the ring</span>
00168 <span class="comment"> * @param hp   The head of the ring</span>
00169 <span class="comment"> */</span>
<a name="l00170"></a><a class="code" href="group__apr__ring.html#ga4">00170</a> <span class="preprocessor">#define APR_RING_LAST(hp)       (hp)-&gt;prev</span>
00171 <span class="preprocessor"></span><span class="comment">/**</span>
00172 <span class="comment"> * The next element in the ring</span>
00173 <span class="comment"> * @param ep   The current element</span>
00174 <span class="comment"> * @param link The name of the APR_RING_ENTRY in the element struct</span>
00175 <span class="comment"> */</span>
<a name="l00176"></a><a class="code" href="group__apr__ring.html#ga5">00176</a> <span class="preprocessor">#define APR_RING_NEXT(ep, link) (ep)-&gt;link.next</span>
00177 <span class="preprocessor"></span><span class="comment">/**</span>
00178 <span class="comment"> * The previous element in the ring</span>
00179 <span class="comment"> * @param ep   The current element</span>
00180 <span class="comment"> * @param link The name of the APR_RING_ENTRY in the element struct</span>
00181 <span class="comment"> */</span>
<a name="l00182"></a><a class="code" href="group__apr__ring.html#ga6">00182</a> <span class="preprocessor">#define APR_RING_PREV(ep, link) (ep)-&gt;link.prev</span>
00183 <span class="preprocessor"></span>
00184 <span class="comment"></span>
00185 <span class="comment">/**</span>
00186 <span class="comment"> * Initialize a ring</span>
00187 <span class="comment"> * @param hp   The head of the ring</span>
00188 <span class="comment"> * @param elem The name of the element struct</span>
00189 <span class="comment"> * @param link The name of the APR_RING_ENTRY in the element struct</span>
00190 <span class="comment"> */</span>
<a name="l00191"></a><a class="code" href="group__apr__ring.html#ga7">00191</a> <span class="preprocessor">#define APR_RING_INIT(hp, elem, link) do {                              \</span>
00192 <span class="preprocessor">        APR_RING_FIRST((hp)) = APR_RING_SENTINEL((hp), elem, link);     \</span>
00193 <span class="preprocessor">        APR_RING_LAST((hp))  = APR_RING_SENTINEL((hp), elem, link);     \</span>
00194 <span class="preprocessor">    } while (0)</span>
00195 <span class="preprocessor"></span><span class="comment"></span>
00196 <span class="comment">/**</span>
00197 <span class="comment"> * Determine if a ring is empty</span>
00198 <span class="comment"> * @param hp   The head of the ring</span>
00199 <span class="comment"> * @param elem The name of the element struct</span>
00200 <span class="comment"> * @param link The name of the APR_RING_ENTRY in the element struct</span>
00201 <span class="comment"> * @return true or false</span>
00202 <span class="comment"> */</span>
<a name="l00203"></a><a class="code" href="group__apr__ring.html#ga8">00203</a> <span class="preprocessor">#define APR_RING_EMPTY(hp, elem, link)                                  \</span>
00204 <span class="preprocessor">    (APR_RING_FIRST((hp)) == APR_RING_SENTINEL((hp), elem, link))</span>
00205 <span class="preprocessor"></span><span class="comment"></span>
00206 <span class="comment">/**</span>
00207 <span class="comment"> * Initialize a singleton element</span>
00208 <span class="comment"> * @param ep   The element</span>
00209 <span class="comment"> * @param link The name of the APR_RING_ENTRY in the element struct</span>
00210 <span class="comment"> */</span>
<a name="l00211"></a><a class="code" href="group__apr__ring.html#ga9">00211</a> <span class="preprocessor">#define APR_RING_ELEM_INIT(ep, link) do {                               \</span>
00212 <span class="preprocessor">        APR_RING_NEXT((ep), link) = (ep);                               \</span>
00213 <span class="preprocessor">        APR_RING_PREV((ep), link) = (ep);                               \</span>
00214 <span class="preprocessor">    } while (0)</span>
00215 <span class="preprocessor"></span>
00216 <span class="comment"></span>
00217 <span class="comment">/**</span>
00218 <span class="comment"> * Splice the sequence ep1..epN into the ring before element lep</span>
00219 <span class="comment"> *   (..lep.. becomes ..ep1..epN..lep..)</span>
00220 <span class="comment"> * @warning This doesn't work for splicing before the first element or on</span>
00221 <span class="comment"> *   empty rings... see APR_RING_SPLICE_HEAD for one that does</span>
00222 <span class="comment"> * @param lep  Element in the ring to splice before</span>
00223 <span class="comment"> * @param ep1  First element in the sequence to splice in</span>
00224 <span class="comment"> * @param epN  Last element in the sequence to splice in</span>
00225 <span class="comment"> * @param link The name of the APR_RING_ENTRY in the element struct</span>
00226 <span class="comment"> */</span>
<a name="l00227"></a><a class="code" href="group__apr__ring.html#ga10">00227</a> <span class="preprocessor">#define APR_RING_SPLICE_BEFORE(lep, ep1, epN, link) do {                \</span>
00228 <span class="preprocessor">        APR_RING_NEXT((epN), link) = (lep);                             \</span>
00229 <span class="preprocessor">        APR_RING_PREV((ep1), link) = APR_RING_PREV((lep), link);        \</span>
00230 <span class="preprocessor">        APR_RING_NEXT(APR_RING_PREV((lep), link), link) = (ep1);        \</span>
00231 <span class="preprocessor">        APR_RING_PREV((lep), link) = (epN);                             \</span>
00232 <span class="preprocessor">    } while (0)</span>
00233 <span class="preprocessor"></span><span class="comment"></span>
00234 <span class="comment">/**</span>
00235 <span class="comment"> * Splice the sequence ep1..epN into the ring after element lep</span>
00236 <span class="comment"> *   (..lep.. becomes ..lep..ep1..epN..)</span>
00237 <span class="comment"> * @warning This doesn't work for splicing after the last element or on</span>
00238 <span class="comment"> *   empty rings... see APR_RING_SPLICE_TAIL for one that does</span>
00239 <span class="comment"> * @param lep  Element in the ring to splice after</span>
00240 <span class="comment"> * @param ep1  First element in the sequence to splice in</span>
00241 <span class="comment"> * @param epN  Last element in the sequence to splice in</span>
00242 <span class="comment"> * @param link The name of the APR_RING_ENTRY in the element struct</span>
00243 <span class="comment"> */</span>
<a name="l00244"></a><a class="code" href="group__apr__ring.html#ga11">00244</a> <span class="preprocessor">#define APR_RING_SPLICE_AFTER(lep, ep1, epN, link) do {                 \</span>
00245 <span class="preprocessor">        APR_RING_PREV((ep1), link) = (lep);                             \</span>
00246 <span class="preprocessor">        APR_RING_NEXT((epN), link) = APR_RING_NEXT((lep), link);        \</span>
00247 <span class="preprocessor">        APR_RING_PREV(APR_RING_NEXT((lep), link), link) = (epN);        \</span>
00248 <span class="preprocessor">        APR_RING_NEXT((lep), link) = (ep1);                             \</span>
00249 <span class="preprocessor">    } while (0)</span>
00250 <span class="preprocessor"></span><span class="comment"></span>
00251 <span class="comment">/**</span>
00252 <span class="comment"> * Insert the element nep into the ring before element lep</span>
00253 <span class="comment"> *   (..lep.. becomes ..nep..lep..)</span>
00254 <span class="comment"> * @warning This doesn't work for inserting before the first element or on</span>
00255 <span class="comment"> *   empty rings... see APR_RING_INSERT_HEAD for one that does</span>
00256 <span class="comment"> * @param lep  Element in the ring to insert before</span>
00257 <span class="comment"> * @param nep  Element to insert</span>
00258 <span class="comment"> * @param link The name of the APR_RING_ENTRY in the element struct</span>
00259 <span class="comment"> */</span>
<a name="l00260"></a><a class="code" href="group__apr__ring.html#ga12">00260</a> <span class="preprocessor">#define APR_RING_INSERT_BEFORE(lep, nep, link)                          \</span>
00261 <span class="preprocessor">        APR_RING_SPLICE_BEFORE((lep), (nep), (nep), link)</span>
00262 <span class="preprocessor"></span><span class="comment"></span>
00263 <span class="comment">/**</span>
00264 <span class="comment"> * Insert the element nep into the ring after element lep</span>
00265 <span class="comment"> *   (..lep.. becomes ..lep..nep..)</span>
00266 <span class="comment"> * @warning This doesn't work for inserting after the last element or on</span>
00267 <span class="comment"> *   empty rings... see APR_RING_INSERT_TAIL for one that does</span>
00268 <span class="comment"> * @param lep  Element in the ring to insert after</span>
00269 <span class="comment"> * @param nep  Element to insert</span>
00270 <span class="comment"> * @param link The name of the APR_RING_ENTRY in the element struct</span>
00271 <span class="comment"> */</span>
<a name="l00272"></a><a class="code" href="group__apr__ring.html#ga13">00272</a> <span class="preprocessor">#define APR_RING_INSERT_AFTER(lep, nep, link)                           \</span>
00273 <span class="preprocessor">        APR_RING_SPLICE_AFTER((lep), (nep), (nep), link)</span>
00274 <span class="preprocessor"></span>
00275 <span class="comment"></span>
00276 <span class="comment">/**</span>
00277 <span class="comment"> * Splice the sequence ep1..epN into the ring before the first element</span>
00278 <span class="comment"> *   (..hp.. becomes ..hp..ep1..epN..)</span>
00279 <span class="comment"> * @param hp   Head of the ring</span>
00280 <span class="comment"> * @param ep1  First element in the sequence to splice in</span>
00281 <span class="comment"> * @param epN  Last element in the sequence to splice in</span>
00282 <span class="comment"> * @param elem The name of the element struct</span>
00283 <span class="comment"> * @param link The name of the APR_RING_ENTRY in the element struct</span>
00284 <span class="comment"> */</span>
<a name="l00285"></a><a class="code" href="group__apr__ring.html#ga14">00285</a> <span class="preprocessor">#define APR_RING_SPLICE_HEAD(hp, ep1, epN, elem, link)                  \</span>
00286 <span class="preprocessor">        APR_RING_SPLICE_AFTER(APR_RING_SENTINEL((hp), elem, link),      \</span>
00287 <span class="preprocessor">                             (ep1), (epN), link)</span>
00288 <span class="preprocessor"></span><span class="comment"></span>
00289 <span class="comment">/**</span>
00290 <span class="comment"> * Splice the sequence ep1..epN into the ring after the last element</span>
00291 <span class="comment"> *   (..hp.. becomes ..ep1..epN..hp..)</span>
00292 <span class="comment"> * @param hp   Head of the ring</span>
00293 <span class="comment"> * @param ep1  First element in the sequence to splice in</span>
00294 <span class="comment"> * @param epN  Last element in the sequence to splice in</span>
00295 <span class="comment"> * @param elem The name of the element struct</span>
00296 <span class="comment"> * @param link The name of the APR_RING_ENTRY in the element struct</span>
00297 <span class="comment"> */</span>
<a name="l00298"></a><a class="code" href="group__apr__ring.html#ga15">00298</a> <span class="preprocessor">#define APR_RING_SPLICE_TAIL(hp, ep1, epN, elem, link)                  \</span>
00299 <span class="preprocessor">        APR_RING_SPLICE_BEFORE(APR_RING_SENTINEL((hp), elem, link),     \</span>
00300 <span class="preprocessor">                             (ep1), (epN), link)</span>
00301 <span class="preprocessor"></span><span class="comment"></span>
00302 <span class="comment">/**</span>
00303 <span class="comment"> * Insert the element nep into the ring before the first element</span>
00304 <span class="comment"> *   (..hp.. becomes ..hp..nep..)</span>
00305 <span class="comment"> * @param hp   Head of the ring</span>
00306 <span class="comment"> * @param nep  Element to insert</span>
00307 <span class="comment"> * @param elem The name of the element struct</span>
00308 <span class="comment"> * @param link The name of the APR_RING_ENTRY in the element struct</span>
00309 <span class="comment"> */</span>
<a name="l00310"></a><a class="code" href="group__apr__ring.html#ga16">00310</a> <span class="preprocessor">#define APR_RING_INSERT_HEAD(hp, nep, elem, link)                       \</span>
00311 <span class="preprocessor">        APR_RING_SPLICE_HEAD((hp), (nep), (nep), elem, link)</span>
00312 <span class="preprocessor"></span><span class="comment"></span>
00313 <span class="comment">/**</span>
00314 <span class="comment"> * Insert the element nep into the ring after the last element</span>
00315 <span class="comment"> *   (..hp.. becomes ..nep..hp..)</span>
00316 <span class="comment"> * @param hp   Head of the ring</span>
00317 <span class="comment"> * @param nep  Element to insert</span>
00318 <span class="comment"> * @param elem The name of the element struct</span>
00319 <span class="comment"> * @param link The name of the APR_RING_ENTRY in the element struct</span>
00320 <span class="comment"> */</span>
<a name="l00321"></a><a class="code" href="group__apr__ring.html#ga17">00321</a> <span class="preprocessor">#define APR_RING_INSERT_TAIL(hp, nep, elem, link)                       \</span>
00322 <span class="preprocessor">        APR_RING_SPLICE_TAIL((hp), (nep), (nep), elem, link)</span>
00323 <span class="preprocessor"></span><span class="comment"></span>
00324 <span class="comment">/**</span>
00325 <span class="comment"> * Concatenate ring h2 onto the end of ring h1, leaving h2 empty.</span>
00326 <span class="comment"> * @param h1   Head of the ring to concatenate onto</span>
00327 <span class="comment"> * @param h2   Head of the ring to concatenate</span>
00328 <span class="comment"> * @param elem The name of the element struct</span>
00329 <span class="comment"> * @param link The name of the APR_RING_ENTRY in the element struct</span>
00330 <span class="comment"> */</span>
<a name="l00331"></a><a class="code" href="group__apr__ring.html#ga18">00331</a> <span class="preprocessor">#define APR_RING_CONCAT(h1, h2, elem, link) do {                        \</span>
00332 <span class="preprocessor">        if (!APR_RING_EMPTY((h2), elem, link)) {                        \</span>
00333 <span class="preprocessor">            APR_RING_SPLICE_BEFORE(APR_RING_SENTINEL((h1), elem, link), \</span>
00334 <span class="preprocessor">                                  APR_RING_FIRST((h2)),                 \</span>
00335 <span class="preprocessor">                                  APR_RING_LAST((h2)), link);           \</span>
00336 <span class="preprocessor">            APR_RING_INIT((h2), elem, link);                            \</span>
00337 <span class="preprocessor">        }                                                               \</span>
00338 <span class="preprocessor">    } while (0)</span>
00339 <span class="preprocessor"></span><span class="comment"></span>
00340 <span class="comment">/**</span>
00341 <span class="comment"> * Prepend ring h2 onto the beginning of ring h1, leaving h2 empty.</span>
00342 <span class="comment"> * @param h1   Head of the ring to prepend onto</span>
00343 <span class="comment"> * @param h2   Head of the ring to prepend</span>
00344 <span class="comment"> * @param elem The name of the element struct</span>
00345 <span class="comment"> * @param link The name of the APR_RING_ENTRY in the element struct</span>
00346 <span class="comment"> */</span>
<a name="l00347"></a><a class="code" href="group__apr__ring.html#ga19">00347</a> <span class="preprocessor">#define APR_RING_PREPEND(h1, h2, elem, link) do {                       \</span>
00348 <span class="preprocessor">        if (!APR_RING_EMPTY((h2), elem, link)) {                        \</span>
00349 <span class="preprocessor">            APR_RING_SPLICE_AFTER(APR_RING_SENTINEL((h1), elem, link),  \</span>
00350 <span class="preprocessor">                                  APR_RING_FIRST((h2)),                 \</span>
00351 <span class="preprocessor">                                  APR_RING_LAST((h2)), link);           \</span>
00352 <span class="preprocessor">            APR_RING_INIT((h2), elem, link);                            \</span>
00353 <span class="preprocessor">        }                                                               \</span>
00354 <span class="preprocessor">    } while (0)</span>
00355 <span class="preprocessor"></span><span class="comment"></span>
00356 <span class="comment">/**</span>
00357 <span class="comment"> * Unsplice a sequence of elements from a ring</span>
00358 <span class="comment"> * @warning The unspliced sequence is left with dangling pointers at either end</span>
00359 <span class="comment"> * @param ep1  First element in the sequence to unsplice</span>
00360 <span class="comment"> * @param epN  Last element in the sequence to unsplice</span>
00361 <span class="comment"> * @param link The name of the APR_RING_ENTRY in the element struct</span>
00362 <span class="comment"> */</span>
<a name="l00363"></a><a class="code" href="group__apr__ring.html#ga20">00363</a> <span class="preprocessor">#define APR_RING_UNSPLICE(ep1, epN, link) do {                          \</span>
00364 <span class="preprocessor">        APR_RING_NEXT(APR_RING_PREV((ep1), link), link) =               \</span>
00365 <span class="preprocessor">                     APR_RING_NEXT((epN), link);                        \</span>
00366 <span class="preprocessor">        APR_RING_PREV(APR_RING_NEXT((epN), link), link) =               \</span>
00367 <span class="preprocessor">                     APR_RING_PREV((ep1), link);                        \</span>
00368 <span class="preprocessor">    } while (0)</span>
00369 <span class="preprocessor"></span><span class="comment"></span>
00370 <span class="comment">/**</span>
00371 <span class="comment"> * Remove a single element from a ring</span>
00372 <span class="comment"> * @warning The unspliced element is left with dangling pointers at either end</span>
00373 <span class="comment"> * @param ep   Element to remove</span>
00374 <span class="comment"> * @param link The name of the APR_RING_ENTRY in the element struct</span>
00375 <span class="comment"> */</span>
<a name="l00376"></a><a class="code" href="group__apr__ring.html#ga21">00376</a> <span class="preprocessor">#define APR_RING_REMOVE(ep, link)                                       \</span>
00377 <span class="preprocessor">    APR_RING_UNSPLICE((ep), (ep), link)</span>
00378 <span class="preprocessor"></span>
00379 
00380 <span class="comment">/* Debugging tools: */</span>
00381 
00382 <span class="preprocessor">#ifdef APR_RING_DEBUG</span>
00383 <span class="preprocessor"></span><span class="preprocessor">#include &lt;stdio.h&gt;</span>
00384 <span class="preprocessor">#include &lt;assert.h&gt;</span>
00385 
00386 <span class="preprocessor">#define APR_RING_CHECK_ONE(msg, ptr)                                    \</span>
00387 <span class="preprocessor">        fprintf(stderr, "*** %s %p\n", msg, ptr)</span>
00388 <span class="preprocessor"></span>
00389 <span class="preprocessor">#define APR_RING_CHECK(hp, elem, link, msg)                             \</span>
00390 <span class="preprocessor">        APR_RING_CHECK_ELEM(APR_RING_SENTINEL(hp, elem, link), elem, link, msg)</span>
00391 <span class="preprocessor"></span>
00392 <span class="preprocessor">#define APR_RING_CHECK_ELEM(ep, elem, link, msg) do {                   \</span>
00393 <span class="preprocessor">        struct elem *start = (ep);                                      \</span>
00394 <span class="preprocessor">        struct elem *here = start;                                      \</span>
00395 <span class="preprocessor">        fprintf(stderr, "*** ring check start -- %s\n", msg);           \</span>
00396 <span class="preprocessor">        do {                                                            \</span>
00397 <span class="preprocessor">            fprintf(stderr, "\telem %p\n", here);                       \</span>
00398 <span class="preprocessor">            fprintf(stderr, "\telem-&gt;next %p\n",                        \</span>
00399 <span class="preprocessor">                    APR_RING_NEXT(here, link));                         \</span>
00400 <span class="preprocessor">            fprintf(stderr, "\telem-&gt;prev %p\n",                        \</span>
00401 <span class="preprocessor">                    APR_RING_PREV(here, link));                         \</span>
00402 <span class="preprocessor">            fprintf(stderr, "\telem-&gt;next-&gt;prev %p\n",                  \</span>
00403 <span class="preprocessor">                    APR_RING_PREV(APR_RING_NEXT(here, link), link));    \</span>
00404 <span class="preprocessor">            fprintf(stderr, "\telem-&gt;prev-&gt;next %p\n",                  \</span>
00405 <span class="preprocessor">                    APR_RING_NEXT(APR_RING_PREV(here, link), link));    \</span>
00406 <span class="preprocessor">            if (APR_RING_PREV(APR_RING_NEXT(here, link), link) != here) { \</span>
00407 <span class="preprocessor">                fprintf(stderr, "\t*** elem-&gt;next-&gt;prev != elem\n");    \</span>
00408 <span class="preprocessor">                break;                                                  \</span>
00409 <span class="preprocessor">            }                                                           \</span>
00410 <span class="preprocessor">            if (APR_RING_NEXT(APR_RING_PREV(here, link), link) != here) { \</span>
00411 <span class="preprocessor">                fprintf(stderr, "\t*** elem-&gt;prev-&gt;next != elem\n");    \</span>
00412 <span class="preprocessor">                break;                                                  \</span>
00413 <span class="preprocessor">            }                                                           \</span>
00414 <span class="preprocessor">            here = APR_RING_NEXT(here, link);                           \</span>
00415 <span class="preprocessor">        } while (here != start);                                        \</span>
00416 <span class="preprocessor">        fprintf(stderr, "*** ring check end\n");                        \</span>
00417 <span class="preprocessor">    } while (0)</span>
00418 <span class="preprocessor"></span>
00419 <span class="preprocessor">#define APR_RING_CHECK_CONSISTENCY(hp, elem, link)                      \</span>
00420 <span class="preprocessor">        APR_RING_CHECK_ELEM_CONSISTENCY(APR_RING_SENTINEL(hp, elem, link),\</span>
00421 <span class="preprocessor">                                        elem, link)</span>
00422 <span class="preprocessor"></span>
00423 <span class="preprocessor">#define APR_RING_CHECK_ELEM_CONSISTENCY(ep, elem, link) do {            \</span>
00424 <span class="preprocessor">        struct elem *start = (ep);                                      \</span>
00425 <span class="preprocessor">        struct elem *here = start;                                      \</span>
00426 <span class="preprocessor">        do {                                                            \</span>
00427 <span class="preprocessor">            assert(APR_RING_PREV(APR_RING_NEXT(here, link), link) == here); \</span>
00428 <span class="preprocessor">            assert(APR_RING_NEXT(APR_RING_PREV(here, link), link) == here); \</span>
00429 <span class="preprocessor">            here = APR_RING_NEXT(here, link);                           \</span>
00430 <span class="preprocessor">        } while (here != start);                                        \</span>
00431 <span class="preprocessor">    } while (0)</span>
00432 <span class="preprocessor"></span>
00433 <span class="preprocessor">#else</span>
00434 <span class="preprocessor"></span><span class="comment">/**</span>
00435 <span class="comment"> * Print a single pointer value to STDERR</span>
00436 <span class="comment"> *   (This is a no-op unless APR_RING_DEBUG is defined.)</span>
00437 <span class="comment"> * @param msg Descriptive message</span>
00438 <span class="comment"> * @param ptr Pointer value to print</span>
00439 <span class="comment"> */</span>
<a name="l00440"></a><a class="code" href="group__apr__ring.html#ga22">00440</a> <span class="preprocessor">#define APR_RING_CHECK_ONE(msg, ptr)</span>
00441 <span class="preprocessor"></span><span class="comment">/**</span>
00442 <span class="comment"> * Dump all ring pointers to STDERR, starting with the head and looping all</span>
00443 <span class="comment"> * the way around the ring back to the head.  Aborts if an inconsistency</span>
00444 <span class="comment"> * is found.</span>
00445 <span class="comment"> *   (This is a no-op unless APR_RING_DEBUG is defined.)</span>
00446 <span class="comment"> * @param hp   Head of the ring</span>
00447 <span class="comment"> * @param elem The name of the element struct</span>
00448 <span class="comment"> * @param link The name of the APR_RING_ENTRY in the element struct</span>
00449 <span class="comment"> * @param msg  Descriptive message</span>
00450 <span class="comment"> */</span>
<a name="l00451"></a><a class="code" href="group__apr__ring.html#ga23">00451</a> <span class="preprocessor">#define APR_RING_CHECK(hp, elem, link, msg)</span>
00452 <span class="preprocessor"></span><span class="comment">/**</span>
00453 <span class="comment"> * Loops around a ring and checks all the pointers for consistency.  Pops</span>
00454 <span class="comment"> * an assertion if any inconsistency is found.  Same idea as APR_RING_CHECK()</span>
00455 <span class="comment"> * except that it's silent if all is well.</span>
00456 <span class="comment"> *   (This is a no-op unless APR_RING_DEBUG is defined.)</span>
00457 <span class="comment"> * @param hp   Head of the ring</span>
00458 <span class="comment"> * @param elem The name of the element struct</span>
00459 <span class="comment"> * @param link The name of the APR_RING_ENTRY in the element struct</span>
00460 <span class="comment"> */</span>
<a name="l00461"></a><a class="code" href="group__apr__ring.html#ga24">00461</a> <span class="preprocessor">#define APR_RING_CHECK_CONSISTENCY(hp, elem, link)</span>
00462 <span class="preprocessor"></span><span class="comment">/**</span>
00463 <span class="comment"> * Dump all ring pointers to STDERR, starting with the given element and</span>
00464 <span class="comment"> * looping all the way around the ring back to that element.  Aborts if</span>
00465 <span class="comment"> * an inconsistency is found.</span>
00466 <span class="comment"> *   (This is a no-op unless APR_RING_DEBUG is defined.)</span>
00467 <span class="comment"> * @param ep   The element</span>
00468 <span class="comment"> * @param elem The name of the element struct</span>
00469 <span class="comment"> * @param link The name of the APR_RING_ENTRY in the element struct</span>
00470 <span class="comment"> * @param msg  Descriptive message</span>
00471 <span class="comment"> */</span>
<a name="l00472"></a><a class="code" href="group__apr__ring.html#ga25">00472</a> <span class="preprocessor">#define APR_RING_CHECK_ELEM(ep, elem, link, msg)</span>
00473 <span class="preprocessor"></span><span class="comment">/**</span>
00474 <span class="comment"> * Loops around a ring, starting with the given element, and checks all</span>
00475 <span class="comment"> * the pointers for consistency.  Pops an assertion if any inconsistency</span>
00476 <span class="comment"> * is found.  Same idea as APR_RING_CHECK_ELEM() except that it's silent</span>
00477 <span class="comment"> * if all is well.</span>
00478 <span class="comment"> *   (This is a no-op unless APR_RING_DEBUG is defined.)</span>
00479 <span class="comment"> * @param ep   The element</span>
00480 <span class="comment"> * @param elem The name of the element struct</span>
00481 <span class="comment"> * @param link The name of the APR_RING_ENTRY in the element struct</span>
00482 <span class="comment"> */</span>
<a name="l00483"></a><a class="code" href="group__apr__ring.html#ga26">00483</a> <span class="preprocessor">#define APR_RING_CHECK_ELEM_CONSISTENCY(ep, elem, link)</span>
00484 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
00485 <span class="preprocessor"></span><span class="comment"></span>
00486 <span class="comment">/** @} */</span> 
00487 
00488 <span class="preprocessor">#endif </span><span class="comment">/* !APR_RING_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&nbsp;
<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>