⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 apr__ring_8h-source.html

📁 apr函数库使用手册
💻 HTML
📖 第 1 页 / 共 3 页
字号:
<!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.7 -->
<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>
<h1>apr_ring.h</h1><a href="apr__ring_8h.html">Go to the documentation of this file.</a><pre class="fragment"><div>00001 <span class="comment">/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as</span>
00002 <span class="comment"> * applicable.</span>
00003 <span class="comment"> *</span>
00004 <span class="comment"> * Licensed under the Apache License, Version 2.0 (the "License");</span>
00005 <span class="comment"> * you may not use this file except in compliance with the License.</span>
00006 <span class="comment"> * You may obtain a copy of the License at</span>
00007 <span class="comment"> *</span>
00008 <span class="comment"> *     http://www.apache.org/licenses/LICENSE-2.0</span>
00009 <span class="comment"> *</span>
00010 <span class="comment"> * Unless required by applicable law or agreed to in writing, software</span>
00011 <span class="comment"> * distributed under the License is distributed on an "AS IS" BASIS,</span>
00012 <span class="comment"> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span>
00013 <span class="comment"> * See the License for the specific language governing permissions and</span>
00014 <span class="comment"> * limitations under the License.</span>
00015 <span class="comment"> */</span>
00016 
00017 <span class="comment">/*</span>
00018 <span class="comment"> * This code draws heavily from the 4.4BSD &lt;sys/queue.h&gt; macros</span>
00019 <span class="comment"> * and Dean Gaudet's "splim/ring.h".</span>
00020 <span class="comment"> * &lt;http://www.freebsd.org/cgi/cvsweb.cgi/src/sys/sys/queue.h&gt;</span>
00021 <span class="comment"> * &lt;http://www.arctic.org/~dean/splim/&gt;</span>
00022 <span class="comment"> *</span>
00023 <span class="comment"> * We'd use Dean's code directly if we could guarantee the</span>
00024 <span class="comment"> * availability of inline functions.</span>
00025 <span class="comment"> */</span>
00026 
00027 <span class="preprocessor">#ifndef APR_RING_H</span>
00028 <span class="preprocessor"></span><span class="preprocessor">#define APR_RING_H</span>
00029 <span class="preprocessor"></span><span class="comment"></span>
00030 <span class="comment">/**</span>
00031 <span class="comment"> * @file apr_ring.h</span>
00032 <span class="comment"> * @brief APR Rings</span>
00033 <span class="comment"> */</span>
00034 
00035 <span class="comment">/*</span>
00036 <span class="comment"> * for offsetof()</span>
00037 <span class="comment"> */</span>
00038 <span class="preprocessor">#include "<a class="code" href="apr__general_8h.html">apr_general.h</a>"</span>
00039 <span class="comment"></span>
00040 <span class="comment">/**</span>
00041 <span class="comment"> * @defgroup apr_ring Ring Macro Implementations</span>
00042 <span class="comment"> * @ingroup APR </span>
00043 <span class="comment"> * A ring is a kind of doubly-linked list that can be manipulated</span>
00044 <span class="comment"> * without knowing where its head is.</span>
00045 <span class="comment"> * @{</span>
00046 <span class="comment"> */</span>
00047 <span class="comment"></span>
00048 <span class="comment">/**</span>
00049 <span class="comment"> * The Ring Element</span>
00050 <span class="comment"> *</span>
00051 <span class="comment"> * A ring element struct is linked to the other elements in the ring</span>
00052 <span class="comment"> * through its ring entry field, e.g.</span>
00053 <span class="comment"> * &lt;pre&gt;</span>
00054 <span class="comment"> *      struct my_element_t {</span>
00055 <span class="comment"> *          APR_RING_ENTRY(my_element_t) link;</span>
00056 <span class="comment"> *          int foo;</span>
00057 <span class="comment"> *          char *bar;</span>
00058 <span class="comment"> *      };</span>
00059 <span class="comment"> * &lt;/pre&gt;</span>
00060 <span class="comment"> *</span>
00061 <span class="comment"> * An element struct may be put on more than one ring if it has more</span>
00062 <span class="comment"> * than one APR_RING_ENTRY field. Each APR_RING_ENTRY has a corresponding</span>
00063 <span class="comment"> * APR_RING_HEAD declaration.</span>
00064 <span class="comment"> *</span>
00065 <span class="comment"> * @warning For strict C standards compliance you should put the APR_RING_ENTRY</span>
00066 <span class="comment"> * first in the element struct unless the head is always part of a larger</span>
00067 <span class="comment"> * object with enough earlier fields to accommodate the offsetof() used</span>
00068 <span class="comment"> * to compute the ring sentinel below. You can usually ignore this caveat.</span>
00069 <span class="comment"> */</span>
<a name="l00070"></a><a class="code" href="group__apr__ring.html#ga0">00070</a> <span class="preprocessor">#define APR_RING_ENTRY(elem)                                            \</span>
00071 <span class="preprocessor">    struct {                                                            \</span>
00072 <span class="preprocessor">        struct elem *next;                                              \</span>
00073 <span class="preprocessor">        struct elem *prev;                                              \</span>
00074 <span class="preprocessor">    }</span>
00075 <span class="preprocessor"></span><span class="comment"></span>
00076 <span class="comment">/**</span>
00077 <span class="comment"> * The Ring Head</span>
00078 <span class="comment"> *</span>
00079 <span class="comment"> * Each ring is managed via its head, which is a struct declared like this:</span>
00080 <span class="comment"> * &lt;pre&gt;</span>
00081 <span class="comment"> *      APR_RING_HEAD(my_ring_t, my_element_t);</span>
00082 <span class="comment"> *      struct my_ring_t ring, *ringp;</span>
00083 <span class="comment"> * &lt;/pre&gt;</span>
00084 <span class="comment"> *</span>
00085 <span class="comment"> * This struct looks just like the element link struct so that we can</span>
00086 <span class="comment"> * be sure that the typecasting games will work as expected.</span>
00087 <span class="comment"> *</span>
00088 <span class="comment"> * The first element in the ring is next after the head, and the last</span>
00089 <span class="comment"> * element is just before the head.</span>
00090 <span class="comment"> */</span>
<a name="l00091"></a><a class="code" href="group__apr__ring.html#ga1">00091</a> <span class="preprocessor">#define APR_RING_HEAD(head, elem)                                       \</span>
00092 <span class="preprocessor">    struct head {                                                       \</span>
00093 <span class="preprocessor">        struct elem *next;                                              \</span>
00094 <span class="preprocessor">        struct elem *prev;                                              \</span>
00095 <span class="preprocessor">    }</span>
00096 <span class="preprocessor"></span><span class="comment"></span>
00097 <span class="comment">/**</span>
00098 <span class="comment"> * The Ring Sentinel</span>
00099 <span class="comment"> *</span>
00100 <span class="comment"> * This is the magic pointer value that occurs before the first and</span>
00101 <span class="comment"> * after the last elements in the ring, computed from the address of</span>
00102 <span class="comment"> * the ring's head.  The head itself isn't an element, but in order to</span>
00103 <span class="comment"> * get rid of all the special cases when dealing with the ends of the</span>
00104 <span class="comment"> * ring, we play typecasting games to make it look like one.</span>
00105 <span class="comment"> *</span>
00106 <span class="comment"> * Here is a diagram to illustrate the arrangements of the next and</span>
00107 <span class="comment"> * prev pointers of each element in a single ring. Note that they point</span>
00108 <span class="comment"> * to the start of each element, not to the APR_RING_ENTRY structure.</span>
00109 <span class="comment"> *</span>
00110 <span class="comment"> * &lt;pre&gt;</span>
00111 <span class="comment"> *     +-&gt;+------+&lt;-+  +-&gt;+------+&lt;-+  +-&gt;+------+&lt;-+</span>
00112 <span class="comment"> *     |  |struct|  |  |  |struct|  |  |  |struct|  |</span>
00113 <span class="comment"> *    /   | elem |   \/   | elem |   \/   | elem |  \</span>
00114 <span class="comment"> * ...    |      |   /\   |      |   /\   |      |   ...</span>
00115 <span class="comment"> *        +------+  |  |  +------+  |  |  +------+</span>
00116 <span class="comment"> *   ...--|prev  |  |  +--|ring  |  |  +--|prev  |</span>
00117 <span class="comment"> *        |  next|--+     | entry|--+     |  next|--...</span>
00118 <span class="comment"> *        +------+        +------+        +------+</span>
00119 <span class="comment"> *        | etc. |        | etc. |        | etc. |</span>
00120 <span class="comment"> *        :      :        :      :        :      :</span>
00121 <span class="comment"> * &lt;/pre&gt;</span>
00122 <span class="comment"> *</span>
00123 <span class="comment"> * The APR_RING_HEAD is nothing but a bare APR_RING_ENTRY. The prev</span>
00124 <span class="comment"> * and next pointers in the first and last elements don't actually</span>
00125 <span class="comment"> * point to the head, they point to a phantom place called the</span>
00126 <span class="comment"> * sentinel. Its value is such that last-&gt;next-&gt;next == first because</span>
00127 <span class="comment"> * the offset from the sentinel to the head's next pointer is the same</span>
00128 <span class="comment"> * as the offset from the start of an element to its next pointer.</span>
00129 <span class="comment"> * This also works in the opposite direction.</span>
00130 <span class="comment"> *</span>
00131 <span class="comment"> * &lt;pre&gt;</span>
00132 <span class="comment"> *        last                            first</span>
00133 <span class="comment"> *     +-&gt;+------+&lt;-+  +-&gt;sentinel&lt;-+  +-&gt;+------+&lt;-+</span>
00134 <span class="comment"> *     |  |struct|  |  |            |  |  |struct|  |</span>
00135 <span class="comment"> *    /   | elem |   \/              \/   | elem |  \</span>
00136 <span class="comment"> * ...    |      |   /\              /\   |      |   ...</span>
00137 <span class="comment"> *        +------+  |  |  +------+  |  |  +------+</span>
00138 <span class="comment"> *   ...--|prev  |  |  +--|ring  |  |  +--|prev  |</span>
00139 <span class="comment"> *        |  next|--+     |  head|--+     |  next|--...</span>
00140 <span class="comment"> *        +------+        +------+        +------+</span>
00141 <span class="comment"> *        | etc. |                        | etc. |</span>
00142 <span class="comment"> *        :      :                        :      :</span>
00143 <span class="comment"> * &lt;/pre&gt;</span>
00144 <span class="comment"> *</span>
00145 <span class="comment"> * Note that the offset mentioned above is different for each kind of</span>
00146 <span class="comment"> * ring that the element may be on, and each kind of ring has a unique</span>
00147 <span class="comment"> * name for its APR_RING_ENTRY in each element, and has its own type</span>
00148 <span class="comment"> * for its APR_RING_HEAD.</span>
00149 <span class="comment"> *</span>
00150 <span class="comment"> * Note also that if the offset is non-zero (which is required if an</span>
00151 <span class="comment"> * element has more than one APR_RING_ENTRY), the unreality of the</span>
00152 <span class="comment"> * sentinel may have bad implications on very perverse implementations</span>
00153 <span class="comment"> * of C -- see the warning in APR_RING_ENTRY.</span>
00154 <span class="comment"> *</span>
00155 <span class="comment"> * @param hp   The head of the ring</span>
00156 <span class="comment"> * @param elem The name of the element struct</span>
00157 <span class="comment"> * @param link The name of the APR_RING_ENTRY in the element struct</span>
00158 <span class="comment"> */</span>
<a name="l00159"></a><a class="code" href="group__apr__ring.html#ga2">00159</a> <span class="preprocessor">#define APR_RING_SENTINEL(hp, elem, link)                               \</span>
00160 <span class="preprocessor">    (struct elem *)((char *)(hp) - APR_OFFSETOF(struct elem, link))</span>
00161 <span class="preprocessor"></span><span class="comment"></span>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -