{"id":1098,"date":"2010-08-13T21:30:38","date_gmt":"2010-08-13T13:30:38","guid":{"rendered":"http:\/\/edsionte.com\/techblog\/?p=1098"},"modified":"2010-08-28T15:24:07","modified_gmt":"2010-08-28T07:24:07","slug":"list-h%e5%a4%b4%e6%96%87%e4%bb%b6%e5%88%86%e6%9e%902","status":"publish","type":"post","link":"http:\/\/edsionte.com\/techblog\/archives\/1098","title":{"rendered":"list.h\u5934\u6587\u4ef6\u5206\u6790(2)"},"content":{"rendered":"<p><strong><em><span style=\"color: #ff0000;\">Last Update:8\/27<\/span><\/em><\/strong><\/p>\n<p><del datetime=\"2010-08-27T10:03:48+00:00\"><strong><em><span style=\"color: #ff0000;\">Last Update:8\/15<\/span><\/em><\/strong><\/del><\/p>\n<p>9.\u5408\u5e76\u94fe\u8868<\/p>\n<p>\u65e2\u7136\u6211\u4eec\u53ef\u4ee5\u5207\u5272\u94fe\u8868\uff0c\u90a3\u4e48\u5f53\u7136\u4e5f\u53ef\u4ee5\u5408\u5e76\u4e86\u3002\u5148\u770b\u6700\u57fa\u672c\u7684\u5408\u5e76\u51fd\u6570\uff0c\u5c31\u662f\u5c06list\u8fd9\u4e2a\u94fe\u8868\uff08\u4e0d\u5305\u62ec\u5934\u7ed3\u70b9\uff09\u63d2\u5165\u5230prev\u548cnext\u4e24\u7ed3\u70b9\u4e4b\u95f4\u3002\u8fd9\u4e2a\u4ee3\u7801\u9605\u8bfb\u8d77\u6765\u4e0d\u56f0\u96be\uff0c\u57fa\u672c\u4e0a\u662f\u201c\u89c1\u7801\u77e5\u610f\u201d\u3002<\/p>\n<pre class=\"brush:c\"> 271static inline void __list_splice(const struct list_head *list,\r\n 272                                 struct list_head *prev,\r\n 273                                 struct list_head *next)\r\n 274{\r\n 275        struct list_head *first = list-&gt;next;\r\n 276        struct list_head *last = list-&gt;prev;\r\n 277\r\n 278        first-&gt;prev = prev;\r\n 279        prev-&gt;next = first;\r\n 280\r\n 281        last-&gt;next = next;\r\n 282        next-&gt;prev = last;\r\n 283}<\/pre>\n<p>\u7406\u89e3\u4e86\u6700\u57fa\u672c\u7684\u5408\u5e76\u51fd\u6570\uff0c\u90a3\u4e48\u5c06\u5b83\u5c01\u88c5\u8d77\u6765\uff0c\u5c31\u53ef\u4ee5\u5f62\u6210\u4e0b\u9762\u4e24\u4e2a\u51fd\u6570\u4e86\uff0c\u5206\u522b\u5728head\u94fe\u8868\u7684\u9996\u90e8\u548c\u5c3e\u90e8\u5408\u5e76\u3002\u8fd9\u91cc\u7684\u8c03\u7528\u8fc7\u7a0b\u7c7b\u4f3c\u589e\u52a0\uff0c\u5220\u9664\u529f\u80fd\u3002<\/p>\n<pre class=\"brush:c\"> 290static inline void list_splice(const struct list_head *list,\r\n 291                                struct list_head *head)\r\n 292{\r\n 293        if (!list_empty(list))\r\n 294                __list_splice(list, head, head-&gt;next);\r\n 295}\r\n\r\n 302static inline void list_splice_tail(struct list_head *list,\r\n 303                                struct list_head *head)\r\n 304{\r\n 305        if (!list_empty(list))\r\n 306                __list_splice(list, head-&gt;prev, head);\r\n 307}<\/pre>\n<p>\u5408\u5e76\u4e24\u4e2a\u94fe\u8868\u540e\uff0clist\u8fd8\u6307\u5411\u539f\u94fe\u8868\uff0c\u56e0\u6b64\u5e94\u8be5\u521d\u59cb\u5316\u3002\u5728\u4e0a\u8ff0\u4e24\u51fd\u6570\u672b\u5c3e\u6dfb\u52a0\u521d\u59cb\u5316\u8bed\u53e5INIT_LIST_HEAD(list);\u540e\uff0c\u5c31\u5b89\u5168\u4e86\u3002<\/p>\n<p>10.\u904d\u5386<\/p>\n<p>\u4e0b\u9762\u6211\u4eec\u8981\u5206\u6790\u94fe\u8868\u7684\u904d\u5386\u3002\u867d\u7136\u6d89\u53ca\u5230\u904d\u5386\u7684\u5b8f\u6bd4\u8f83\u591a\uff0c\u4f46\u662f\u6839\u636e\u6211\u4eec\u524d\u9762\u5206\u6790\u7684\u90a3\u6837\uff0c\u638c\u63e1\u597d\u6700\u57fa\u672c\u7684\u5b8f\uff0c\u5176\u4ed6\u5b8f\u5c31\u662f\u8fdb\u884c\u201c\u5c01\u88c5\u201d\u3002\u4fbf\u5229\u4e2d\u7684\u57fa\u672c\u5b8f\u662f\uff1a<\/p>\n<pre class=\"brush:c\">381#define __list_for_each(pos, head) \\\r\n382        for (pos = (head)-&gt;next; pos != (head); pos = pos-&gt;next)<\/pre>\n<p>head\u662f\u6574\u4e2a\u94fe\u8868\u7684\u5934\u6307\u9488\uff0c\u800cpos\u5219\u4e0d\u505c\u7684\u5f80\u540e\u79fb\u52a8\u3002\u4f46\u662f\u4f60\u6709\u6ca1\u6709\u89c9\u5f97\uff0c\u8fd9\u91cc\u6709\u4e9b\u5947\u602a\uff1f\u56e0\u4e3a\u6211\u4eec\u5728\u4e0a\u7bc7\u6587\u7ae0\u4e2d\u8bf4\u8fc7\uff0cstruct list_head\u7ed3\u6784\u7ecf\u5e38\u548c\u5176\u4ed6\u6570\u636e\u7ec4\u6210\u65b0\u7684\u7ed3\u6784\u4f53\uff0c\u90a3\u4e48\u73b0\u5728\u6211\u4eec\u53ea\u662f\u4e0d\u505c\u7684\u904d\u5386\u65b0\u7ed3\u6784\u4f53\u4e2d\u7684\u6307\u9488\uff0c\u5982\u4f55\u5f97\u5230\u5176\u4ed6\u6210\u5458\uff1f\u56e0\u6b64\u6211\u4eec\u9700\u8981\u641e\u61c2list_entry\u8fd9\u4e2a\u5b8f\uff1a<\/p>\n<pre class=\"brush:c\"> 348#define list_entry(ptr, type, member) \\\r\n 349        container_of(ptr, type, member)<\/pre>\n<p>\u8fd9\u4e2a\u5b8f\u7684\u4f5c\u7528\u662f\u901a\u8fc7ptr\u6307\u9488\u83b7\u53d6type\u7ed3\u6784\u7684\u5730\u5740\uff0c\u4e5f\u5c31\u662f\u6307\u5411type\u7684\u6307\u9488\u3002\u5176\u4e2dptr\u662f\u6307\u5411member\u6210\u5458\u7684\u6307\u9488\u3002\u8fd9\u4e2alist_entry\u5b8f\u8c8c\u4f3c\u5f88\u7b80\u5355\u7684\u6837\u5b50\uff0c\u5c31\u662f\u518d\u8c03\u7528container_of\u5b8f\uff0c\u53ef\u662f\u5f53\u4f60\u770b\u4e86container_of\u5b8f\u7684\u5b9a\u4e49\u540e\u2026\u2026<\/p>\n<pre class=\"brush:c\"> 443#define container_of(ptr, type, member) ({                      \\\r\n 444        const typeof( ((type *)0)-&gt;member ) *__mptr = (ptr);    \\\r\n 445        (type *)( (char *)__mptr - offsetof(type,member) );})<\/pre>\n<p>\u662f\u4e0d\u662f\u8ba9\u4eba\u6709\u70b9\u6293\u72c2\uff1f\u522b\u6025\uff0c\u6211\u4eec\u4e00\u70b9\u70b9\u6765\u5206\u6790\u3002<\/p>\n<p>\u9996\u5148\u8fd9\u4e2a\u5b8f\u5305\u542b\u4e24\u6761\u8bed\u53e5\u3002\u7b2c\u4e00\u6761\uff1aconst  typeof( ((type *)0)-&gt;member ) *__mptr = (ptr);\u9996\u5148\u5c060\u8f6c\u5316\u6210type\u7c7b\u578b\u7684\u6307\u9488\u53d8\u91cf\uff08\u8fd9\u4e2a\u6307\u9488\u53d8\u91cf\u7684\u5730\u5740\u4e3a0x0\uff09\uff0c\u7136\u540e\u518d\u5f15\u7528member\u6210\u5458\uff08\u5bf9\u5e94\u5c31\u662f((type *)0)-&gt;member )\uff09\u3002\u6ce8\u610f\u8fd9\u91cc\u7684typeof\uff08x\uff09\uff0c\u662f\u8fd4\u56dex\u7684\u6570\u636e\u7c7b\u578b\uff0c\u90a3\u4e48 typeof( ((type *)0)-&gt;member )\u5176\u5b9e\u5c31\u662f\u8fd4\u56demember\u6210\u5458\u7684\u6570\u636e\u7c7b\u578b\u3002\u90a3\u4e48\u8fd9\u6761\u8bed\u53e5\u6574\u4f53\u5c31\u662f\u5c06__mptr\u5f3a\u5236\u8f6c\u6362\u6210member\u6210\u5458\u7684\u6570\u636e\u7c7b\u578b\uff0c\u518d\u5c06ptr\u7684\u8d4b\u7ed9\u5b83(ptr\u672c\u8eab\u5c31\u662f\u6307\u5411member\u7684\u6307\u9488)\u3002<\/p>\n<p>\u7b2c\u4e8c\u53e5\u4e2d\uff0c\u6211\u4eec\u5148\u4e86\u89e3offsetof\u662f\u4ec0\u4e48\uff1f\u5b83\u4e5f\u662f\u4e00\u4e2a\u5b8f\u88ab\u5b9a\u4e49\u5728\uff1alinux\/include\/stddef.h\u4e2d\u3002\u539f\u578b\u4e3a\uff1a<\/p>\n<pre class=\"brush:c\">#define offsetof(TYPE, MEMBER) ((size_t) &amp;((TYPE *)0)-&gt;MEMBER);<\/pre>\n<p>\u8fd9\u4e2a\u8c8c\u4f3c\u4e5f\u5f88\u6293\u72c2\uff0c\u4e0d\u8fc7\u8010\u5fc3\u8010\u5fc3\uff1a((TYPE *)0)-&gt;MEMBER)\u8fd9\u4e2a\u5176\u5b9e\u5c31\u662f\u63d0\u53d6type\u7c7b\u578b\u4e2d\u7684member\u6210\u5458\uff0c\u90a3\u4e48&amp;((TYPE *)0)-&gt;MEMBER)\u5f97\u5230member\u6210\u5458\u7684\u5730\u5740\uff0c\u518d\u5f3a\u5236\u8f6c\u6362\u6210size_t\u7c7b\u578b\uff08unsigned int\uff09\u3002\u4f46\u662f\u8fd9\u4e2a\u5730\u5740\u5f88\u7279\u522b\uff0c\u56e0\u4e3aTYPE\u7c7b\u578b\u662f\u4ece0x0\u5f00\u59cb\u5b9a\u4e49\u7684\uff0c\u90a3\u4e48\u6211\u4eec\u73b0\u5728\u5f97\u5230\u7684\u8fd9\u4e2a\u5730\u5740\u5c31\u662fmember\u6210\u5458\u5728TYPE\u6570\u636e\u7c7b\u578b\u4e2d\u7684\u504f\u79fb\u91cf\u3002<\/p>\n<p>\u6211\u4eec\u518d\u6765\u770b\u7b2c\u4e8c\u6761\u8bed\u53e5\uff0c (type *)( (char *)__mptr &#8211; offsetof(type,member) )\u6c42\u7684\u5c31\u662ftype\u7684\u5730\u5740\uff0c\u5373\u6307\u5411type\u7684\u6307\u9488\u3002<span style=\"color: #ff0000;\">\u4e0d\u8fc7\u8fd9\u91cc\u8981\u6ce8\u610f__mptr\u88ab\u5f3a\u5236\u8f6c\u6362\u6210\u4e86(char *)\uff0c\u4e3a\u4f55\u8981\u8fd9\u4e48\u505a\uff1f\u56e0\u4e3a\u5982\u679cmember\u662f\u975echar\u578b\u7684\u53d8\u91cf\uff0c\u6bd4\u5982\u4e3aint\u578b\uff0c\u5e76\u4e14\u5047\u8bbe\u8fd4\u56de\u503c\u4e3aoffset\uff0c\u90a3\u4e48\u8fd9\u6837\u76f4\u63a5\u51cf\u53bb\u504f\u79fb\u91cf\uff0c\u5b9e\u9645\u4e0a__mptr\u4f1a\u51cf\u53bbsizeof(int)*offset\uff01\u8fd9\u4e00\u70b9\u548c\u6307\u9488\u52a0\u4e00\u51cf\u4e00\u7684\u539f\u7406\u76f8\u540c\u3002<\/span><\/p>\n<p>\u6709\u4e86\u8fd9\u4e2a\u6307\u9488\uff0c\u90a3\u4e48\u5c31\u53ef\u4ee5\u968f\u610f\u5f15\u7528\u5176\u5185\u7684\u6210\u5458\u4e86\u3002\u5173\u4e8e\u6b64\u5b8f\u7684\u66f4\u5177\u4f53\u4e86\u89e3\uff0c\u4e0d\u59a8\u4eb2\u81ea\u52a8\u624b\u6d4b\u8bd5<a href=\"http:\/\/www.kerneltravel.net\/?p=365\" target=\"_blank\">\u8fd9\u91cc<\/a>\u7684\u7a0b\u5e8f\u3002<\/p>\n<p>\u597d\u4e86\uff0c\u73b0\u5728\u4e0d\u7528\u6293\u72c2\u4e86\uff0c\u56e0\u4e3a\u4e86\u89e3\u4e86list_entry\u5b8f\uff0c\u63a5\u4e0b\u6765\u7684\u4e8b\u60c5\u5c31\u5f88\u7b80\u5355\u4e86\u3002<\/p>\n<p>\u4e0b\u9762\u8fd9\u4e2a\u5b8f\u4f1a\u5f97\u5230\u94fe\u8868\u4e2d\u7b2c\u4e00\u4e2a\u7ed3\u70b9\u7684\u5730\u5740\u3002<\/p>\n<pre class=\"brush:c\"> 359#define list_first_entry(ptr, type, member) \\\r\n 360        list_entry((ptr)-&gt;next, type, member)<\/pre>\n<p>\u771f\u6b63\u904d\u5386\u7684\u5b8f\u767b\u573a\u4e86\uff0c\u6574\u4e2a\u4fbf\u5229\u8fc7\u7a0b\u770b\u8d77\u6765\u5f88\u7b80\u5355\uff0c\u53ef\u80fd\u4f60\u5bf9prefetch()\u964c\u751f\uff0c\u5b83\u7684\u4f5c\u7528\u662f\u9884\u53d6\u8282\u70b9\uff0c\u4ee5\u63d0\u9ad8\u901f\u5ea6\u3002<\/p>\n<pre class=\"brush:c\"> 367#define list_for_each(pos, head) \\\r\n 368        for (pos = (head)-&gt;next; prefetch(pos-&gt;next), pos != (head); \\\r\n 369                pos = pos-&gt;next)<\/pre>\n<p>\u6211\u4eec\u518d\u6765\u770b\u4e00\u5f00\u59cb\u6211\u4eec\u4e3e\u4f8b\u7684\u90a3\u4e2a\u4fbf\u5229\u5b8f\u3002\u6ce8\u610f\u5b83\u548c\u4e0a\u8ff0\u4fbf\u5229\u5b8f\u7684\u533a\u522b\u5c31\u662f\u6ca1\u6709prefetch()\uff0c\u56e0\u4e3a\u8fd9\u4e2a\u5b8f\u9002\u5408\u6bd4\u8f83\u5c11\u7ed3\u70b9\u7684\u94fe\u8868\u3002<\/p>\n<pre class=\"brush:c\"> 381#define __list_for_each(pos, head) \\\r\n 382        for (pos = (head)-&gt;next; pos != (head); pos = pos-&gt;next)<\/pre>\n<p>\u63a5\u4e0b\u6765\u8fd9\u4e2a\u904d\u5386\u5b8f\u8c8c\u4f3c\u957f\u76f8\u548c\u4e0a\u9762\u90a3\u51e0\u4e2a\u7a0d\u6709\u4e0d\u540c\uff0c\u4e0d\u8fc7\u7406\u89e3\u8d77\u6765\u4e5f\u4e0d\u56f0\u96be\uff0c\u5012\u7740\uff08\u4ece\u6700\u540e\u4e00\u4e2a\u7ed3\u70b9\uff09\u5f00\u59cb\u904d\u5386\u94fe\u8868\u3002<\/p>\n<pre class=\"brush:c\">389#define list_for_each_prev(pos, head) \\\r\n 390        for (pos = (head)-&gt;prev; prefetch(pos-&gt;prev), pos != (head); \\\r\n 391                pos = pos-&gt;prev)<\/pre>\n<p>\u4e0b\u9762\u4e24\u4e2a\u5b8f\u662f\u4e0a\u8ff0\u4e24\u4e2a\u4fbf\u5229\u5b8f\u7684\u5b89\u5168\u7248\uff0c\u6211\u4eec\u770b\u5b83\u5b89\u5168\u5728\u90a3\u91cc\uff1f\u5b83\u591a\u4e86\u4e00\u4e2a\u4e0epos\u540c\u7c7b\u578b\u7684n\uff0c\u6bcf\u6b21\u5c06\u4e0b\u4e00\u4e2a\u7ed3\u70b9\u7684\u6307\u9488\u6682\u5b58\u8d77\u6765\uff0c\u9632\u6b62pos\u88ab\u91ca\u653e\u65f6\u5f15\u8d77\u7684\u94fe\u8868\u65ad\u88c2\u3002<\/p>\n<pre class=\"brush:c\">399#define list_for_each_safe(pos, n, head) \\\r\n 400        for (pos = (head)-&gt;next, n = pos-&gt;next; pos != (head); \\\r\n 401                pos = n, n = pos-&gt;next)\r\n\r\n 409#define list_for_each_prev_safe(pos, n, head) \\\r\n 410        for (pos = (head)-&gt;prev, n = pos-&gt;prev; \\\r\n 411             prefetch(pos-&gt;prev), pos != (head); \\\r\n 412             pos = n, n = pos-&gt;prev)<\/pre>\n<p>\u524d\u9762\u6211\u4eec\u8bf4\u8fc7\uff0c\u7528\u5728list_for_each\u5b8f\u8fdb\u884c\u904d\u5386\u7684\u65f6\u5019\uff0c\u6211\u4eec\u5f88\u5bb9\u6613\u5f97\u5230pos\uff0c\u6211\u4eec\u90fd\u77e5\u9053pos\u5b58\u50a8\u7684\u662f\u5f53\u524d\u7ed3\u70b9\u524d\u540e\u4e24\u4e2a\u7ed3\u70b9\u7684\u5730\u5740\u3002\u800c\u901a\u8fc7list_entry\u5b8f\u53ef\u4ee5\u83b7\u5f97\u5f53\u524d\u7ed3\u70b9\u7684\u5730\u5740\uff0c\u8fdb\u800c\u5f97\u5230\u8fd9\u4e2a\u7ed3\u70b9\u4e2d\u5176\u4ed6\u7684\u6210\u5458\u53d8\u91cf\u3002\u800c\u4e0b\u9762\u4e24\u4e2a\u5b8f\u5219\u53ef\u4ee5\u76f4\u63a5\u83b7\u5f97\u6bcf\u4e2a\u7ed3\u70b9\u7684\u5730\u5740\uff0c\u6211\u4eec\u63a5\u4e0b\u6765\u770b\u5b83\u662f\u5982\u4f55\u5b9e\u73b0\u7684\u3002\u4e3a\u4e86\u65b9\u4fbf\u8bf4\u660e\u4ee5\u53ca\u4fbf\u4e8e\u7406\u89e3\uff0c\u6211\u4eec\u7528\u4e0a\u6587\u4e2d\u7684\u7ed3\u6784struct stu\u6765\u4e3e\u4f8b\u3002pos\u662f\u6307\u5411struct stu\u7ed3\u6784\u7684\u6307\u9488\uff1blist\u662f\u4e00\u4e2a\u53cc\u94fe\u8868\uff0c\u540c\u65f6\u4e5f\u662f\u8fd9\u4e2a\u7ed3\u6784\u4e2d\u7684\u6210\u5458\uff0chead\u4fbf\u6307\u5411\u8fd9\u4e2a\u53cc\u94fe\u8868\uff1bmember\u5176\u5b9e\u5c31\u662f\u8fd9\u4e2a\u7ed3\u6784\u4f53\u4e2d\u7684list\u6210\u5458\u3002<\/p>\n<p>\u5728for\u5faa\u73af\u4e2d\uff0c\u9996\u5148\u901a\u8fc7list_entry\u6765\u83b7\u5f97\u7b2c\u4e00\u4e2a\u7ed3\u70b9\u7684\u5730\u5740\uff1b&amp;pos-&gt;member != (head)\u5176\u5b9e\u5c31\u662f&amp;pos-&gt;list!=(head)\uff1b\u5b83\u662f\u7528\u6765\u68c0\u6d4b\u5f53\u524dlist\u94fe\u8868\u662f\u5426\u5230\u5934\u4e86\uff1b\u6700\u540e\u5728\u5229\u7528list_entry\u5b8f\u6765\u83b7\u5f97\u4e0b\u4e00\u4e2a\u7ed3\u70b9\u7684\u5730\u5740\u3002\u8fd9\u6837\u6574\u4e2afor\u5faa\u73af\u5c31\u53ef\u4ee5\u4f9d\u6b21\u83b7\u5f97\u6bcf\u4e2a\u7ed3\u70b9\u7684\u5730\u5740\uff0c\u8fdb\u800c\u518d\u53bb\u83b7\u5f97\u5176\u4ed6\u6210\u5458\u3002\u7406\u89e3\u4e86list_for_each_entry\u5b8f\uff0c\u90a3\u4e48list_for_each_entry_reverse\u5b8f\u5c31\u663e\u800c\u6613\u89c1\u4e86\u3002<\/p>\n<pre class=\"brush:c\"> 420#define list_for_each_entry(pos, head, member)                          \\\r\n 421        for (pos = list_entry((head)-&gt;next, typeof(*pos), member);      \\\r\n 422             prefetch(pos-&gt;member.next), &amp;pos-&gt;member != (head);        \\\r\n 423             pos = list_entry(pos-&gt;member.next, typeof(*pos), member))\r\n\r\n 431#define list_for_each_entry_reverse(pos, head, member)                  \\\r\n 432        for (pos = list_entry((head)-&gt;prev, typeof(*pos), member);      \\\r\n 433             prefetch(pos-&gt;member.prev), &amp;pos-&gt;member != (head);        \\\r\n 434             pos = list_entry(pos-&gt;member.prev, typeof(*pos), member))<\/pre>\n<p>\u4e0b\u9762\u8fd9\u4e24\u4e2a\u5b8f\u662f\u4ece\u5f53\u524d\u7ed3\u70b9\u7684\u4e0b\u4e00\u4e2a\u7ed3\u70b9\u5f00\u59cb\u7ee7\u7eed\uff08\u6216\u53cd\u5411\uff09\u904d\u5386\u3002<\/p>\n<pre class=\"brush:c\"> 456#define list_for_each_entry_continue(pos, head, member)                 \\\r\n 457        for (pos = list_entry(pos-&gt;member.next, typeof(*pos), member);  \\\r\n 458             prefetch(pos-&gt;member.next), &amp;pos-&gt;member != (head);        \\\r\n 459             pos = list_entry(pos-&gt;member.next, typeof(*pos), member))\r\n\r\n 470#define list_for_each_entry_continue_reverse(pos, head, member)         \\\r\n 471        for (pos = list_entry(pos-&gt;member.prev, typeof(*pos), member);  \\\r\n 472             prefetch(pos-&gt;member.prev), &amp;pos-&gt;member != (head);        \\\r\n 473             pos = list_entry(pos-&gt;member.prev, typeof(*pos), member))<\/pre>\n<p>\u4e0e\u4e0a\u8ff0\u5b8f\u4e0d\u540c\u7684\u662f\uff0c\u8fd9\u4e2a\u5b8f\u662f\u4ece\u5f53\u524dpos\u7ed3\u70b9\u5f00\u59cb\u904d\u5386\u3002<\/p>\n<pre class=\"brush:c\"> 483#define list_for_each_entry_from(pos, head, member)                     \\\r\n 484        for (; prefetch(pos-&gt;member.next), &amp;pos-&gt;member != (head);      \\\r\n 485             pos = list_entry(pos-&gt;member.next, typeof(*pos), member))<\/pre>\n<p>\u63a5\u4e0b\u6765\u51e0\u4e2a\u5b8f\u53c8\u5206\u522b\u662f\u4e0a\u8ff0\u51e0\u4e2a\u5b8f\u7684\u5b89\u5168\u7248\u3002\u5b89\u5168\u539f\u56e0\u4e0a\u9762\u5df2\u7ecf\u8bf4\u8fc7\uff0c\u5728\u6b64\u4e0d\u518d\u8d58\u8ff0\u3002<\/p>\n<pre class=\"brush:c\">list_for_each_entry_safe(pos, n, head, member)\r\nlist_for_each_entry_safe_continue(pos, n, head, member)\r\nlist_for_each_entry_safe_from(pos, n, head, member)\r\nlist_for_each_entry_safe_reverse(pos, n, head, member)<\/pre>\n<p>\u4ee5\u4e0a\u5373\u662flist.h\u5934\u6587\u4ef6\u4e2d\u7684\u5927\u90e8\u5206\u5185\u5bb9\u5206\u6790\u3002\u5173\u4e8ehash\u8868\u90e8\u5206\u5728\u6b64\u6682\u4e0d\u5206\u6790\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Last Update:8\/27 Last Update:8\/15 9.\u5408\u5e76\u94fe\u8868 \u65e2\u7136\u6211\u4eec\u53ef\u4ee5\u5207\u5272\u94fe\u8868\uff0c\u90a3\u4e48\u5f53 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[110],"tags":[134,108,135],"class_list":["post-1098","post","type-post","status-publish","format-standard","hentry","category-linux","tag-kernel","tag-linux","tag-135"],"views":18042,"_links":{"self":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts\/1098","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/comments?post=1098"}],"version-history":[{"count":0,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts\/1098\/revisions"}],"wp:attachment":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/media?parent=1098"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/categories?post=1098"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/tags?post=1098"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}