{"id":1074,"date":"2010-08-12T15:04:19","date_gmt":"2010-08-12T21:04:19","guid":{"rendered":"http:\/\/edsionte.com\/techblog\/?p=1074"},"modified":"2012-07-06T10:55:03","modified_gmt":"2012-07-06T02:55:03","slug":"list-h%e5%a4%b4%e6%96%87%e4%bb%b6%e5%88%86%e6%9e%90","status":"publish","type":"post","link":"http:\/\/edsionte.com\/techblog\/archives\/1074","title":{"rendered":"list.h\u5934\u6587\u4ef6\u5206\u6790(1)"},"content":{"rendered":"<p><strong><em><span style=\"color: #ff0000;\">Last Update\uff1a 8\/15<\/span><\/em><\/strong><\/p>\n<p>\u53cc\u94fe\u8868\u7684\u5e94\u7528\u5728\u5185\u6838\u4e2d\u968f\u5904\u53ef\u89c1\uff0clist.h\u5934\u6587\u4ef6\u96c6\u4e2d\u5b9a\u4e49\u4e86\u53cc\u94fe\u8868\uff08struct list_head\u7ed3\u6784\u4f53\uff09\u7684\u76f8\u5173\u64cd\u4f5c\u3002\u6bd4\u5982<a href=\"http:\/\/lxr.linux.no\/linux+v2.6.35\/include\/linux\/fs.h\" target=\"_blank\">\u8fd9\u91cc<\/a>\u7684\u4e00\u4e2a\u5934\u6587\u4ef6\u4e2d\u5c31\u6709\u5927\u91cf\u7684struct list_head\u578b\u7684\u6570\u636e\u3002<\/p>\n<p>\u5173\u4e8elist.h\u7684\u5206\u6790\uff0c\u7f51\u4e0a\u8d44\u6599\u5f88\u591a\uff0c\u8fd9\u91cc\u53ea\u662f\u8bb0\u5f55\u6211\u5728\u5206\u6790list.h\u4e2d\u9047\u5230\u7684\u95ee\u9898\u3002<\/p>\n<p>0.struct list_head\u7ed3\u6784\u4f53<\/p>\n<p>\u53ef\u80fd\u8fd9\u6837\u5199\uff0c\u66f4\u8ba9\u6211\u4eec\u4e60\u60ef\uff1a<\/p>\n<pre class=\"brush:c\">struct list_head {\r\nstruct list_head *next;\r\nstruct list_head *prev;\r\n};<\/pre>\n<p><strong>\u8fd9\u4e2a\u7ed3\u6784\u7ecf\u5e38\u4f5c\u4e3a\u6210\u5458\u4e0e\u5176\u4ed6\u6570\u636e\u7c7b\u578b\u4e00\u8d77\u7ec4\u6210\u4e00\u4e2a\u65b0\u7684\u7ed3\u6784\u4f53\uff08\u540e\u6587\u82e5\u65e0\u7279\u522b\u63d0\u793a\uff0c\u201c\u65b0\u7ed3\u6784\u4f53\u201d\u5747\u6307\u7c7b\u4f3c\u4e0b\u9762\u4e3e\u4f8b\u7684\u5d4c\u5957\u578b\u7ed3\u6784\u4f53\uff09<\/strong>\uff0c\u6bd4\u5982:<\/p>\n<pre class=\"brush:c\">struct stu\r\n{\r\n\tchar name[20];\r\n\tint id;\r\n\tstruct list_head list;\r\n}<\/pre>\n<p>\u6211\u4eec\u5df2\u7ecf\u770b\u5230\uff0cstruct list_head\u8fd9\u4e2a\u7ed3\u6784\u6bd4\u8f83\u7279\u6b8a\uff0c\u5b83\u5185\u90e8\u6ca1\u6709\u4efb\u4f55\u6570\u636e\uff0c\u53ea\u662f\u8d77\u5230\u94fe\u63a5\u94fe\u8868\u7684\u4f5c\u7528\u3002\u5bf9\u4e8e\u5b83\u5f53\u524d\u6240\u5728\u7684\u8fd9\u4e2a\u7ed3\u70b9\u6765\u8bf4\uff0cnext\u6307\u5411\u4e0b\u4e00\u4e2a\u7ed3\u70b9\uff0cprev\u6307\u5411\u4e0a\u4e00\u4e2a\u7ed3\u70b9\u3002\u901a\u5e38\u6211\u4eec\u901a\u8fc7\u6307\u5411struc list_head\u7684\u6307\u9488pos\u6765\u83b7\u53d6\u5b83\u6240\u5728\u7ed3\u70b9\u7684\u5730\u5740\uff0c\u5c3d\u800c\u83b7\u53d6\u5176\u4ed6\u6570\u636e\u3002\u4e5f\u8bb8\u4f60\u73b0\u5728\u8fd8\u6bd4\u8f83\u56f0\u60d1\u8fd9\u4e00\u8fc7\u7a0b\uff0c\u522b\u7740\u6025\uff0c\u540e\u9762\u6709\u7279\u522b\u89e3\u91ca\u3002<\/p>\n<p>1.\u94fe\u8868\u7684\u521d\u59cb\u5316<\/p>\n<p>\u5176\u5b9e\u53ef\u4ee5\u4ece\u540e\u5f80\u524d\u770b\uff0c\u8fd9\u6837\u66f4\u5bb9\u6613\u7406\u89e3\u3002INIT_LIST_HEAD\u51fd\u6570\u5f62\u6210\u4e00\u4e2a\u7a7a\u94fe\u8868\u3002\u8fd9\u4e2alist\u53d8\u91cf\u4e00\u822c\u4f5c\u4e3a\u5934\u6307\u9488\uff08\u975e\u5934\u7ed3\u70b9\uff09\u3002<\/p>\n<pre class=\"brush:c\">  28static inline void INIT_LIST_HEAD(struct list_head *list)\r\n  29{\r\n  30        list-&gt;next = list;\r\n  31        list-&gt;prev = list;\r\n  32}<\/pre>\n<p>\u4e0b\u9762\u7684\u5b8f\u751f\u6210\u4e00\u4e2a\u5934\u6307\u9488name\uff0c\u5982\u4f55\u751f\u6210\uff1f\u8bf7\u770bLIST_HEAD_INIT(name)\u3002<\/p>\n<pre class=\"brush:c\">  25#define LIST_HEAD(name) \\\r\n  26        struct list_head name = LIST_HEAD_INIT(name)<\/pre>\n<p>LIST_HEAD_INIT(name)\u5c06name\u7684\u5730\u5740\u76f4\u63a5\u5206\u522b\u8d4b\u503c\u7ed9next\u548cprev\uff0c\u90a3\u4e48\u5b83\u4eec\u4e8b\u5b9e\u4e0a\u90fd\u6307\u5411\u81ea\u5df1\uff0c\u4e5f\u5f62\u6210\u4e00\u4e2a\u7a7a\u94fe\u8868\u3002\u73b0\u5728\u518d\u56de\u5934\u770b\u5b8fLIST_HEAD(name)\uff0c\u5b83\u5176\u5b9e\u5c31\u662f\u4e00\u4e2a\u5b9a\u4e49\u5e76\u521d\u59cb\u5316\u4f5c\u7528\u3002<\/p>\n<pre class=\"brush:c\">  23#define LIST_HEAD_INIT(name) { &amp;(name), &amp;(name) }<\/pre>\n<p>3.\u6dfb\u52a0\u5143\u7d20<\/p>\n<p>\u8fd9\u4e24\u4e2a\u51fd\u6570\u5206\u522b\u7ed9\u94fe\u8868\u5934\u7ed3\u70b9\u540e\uff0c\u5934\u7ed3\u70b9\u524d\u6dfb\u52a0\u5143\u7d20\u3002\u524d\u8005\u53ef\u5b9e\u73b0\u6808\u7684\u6dfb\u52a0\u5143\u7d20\uff0c\u540e\u8005\u53ef\u5b9e\u73b0\u961f\u5217\u7684\u6dfb\u52a0\u5143\u7d20\u3002<br \/>\nstatic inline void list_add(struct list_head *new, struct list_head *head);<br \/>\nstatic inline void list_add_tail(struct list_head *new, struct list_head *head);<\/p>\n<p>\u8fd9\u4e24\u4e2a\u51fd\u6570\u5982\u4f55\u5b9e\u73b0\u7684\uff1f\u5b83\u4eec\u5747\u8c03\u7528\u7684\u4e0b\u9762\u51fd\u6570\uff1a<\/p>\n<pre class=\"brush:c\">  41static inline void __list_add(struct list_head *new,\r\n  42                              struct list_head *prev,\r\n  43                              struct list_head *next)\r\n  44{\r\n  45        next-&gt;prev = new;\r\n  46        new-&gt;next = next;\r\n  47        new-&gt;prev = prev;\r\n  48        prev-&gt;next = new;\r\n  49}<\/pre>\n<p>\u73b0\u5728\u6211\u4eec\u8981\u5173\u6ce8\u7684\u662f\uff0clist_add\u548clist_add_tail\u4e24\u51fd\u6570\u5728\u8c03\u7528<span style=\"font-family: Consolas, Monaco, 'Courier New', Courier, monospace; line-height: 18px; font-size: 12px; white-space: pre;\">__list_add<span style=\"font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 19px; white-space: normal; font-size: 13px;\">\u51fd\u6570\u65f6\uff0c\u5bf9\u5e94\u7684\u5404\u4e2a\u53c2\u6570\u5206\u522b\u662f\u4ec0\u4e48\uff1f\u901a\u8fc7\u4e0b\u9762\u6240\u5217\u4ee3\u7801\uff0c\u6211\u4eec\u53ef\u4ee5\u53d1\u73b0\u8fd9\u91cc\u7684\u53c2\u6570\u8fd0\u7528\u7684\u5f88\u5de7\u5999\uff0c\u7c7b\u4f3cJAVA\u4e2d\u7684\u5c01\u88c5\u3002<\/span><\/span><\/p>\n<pre class=\"brush:c\">  64static inline void list_add(struct list_head *new, struct list_head *head)\r\n  65{\r\n  66        __list_add(new, head, head-&gt;next);\r\n  67}\r\n\r\n  78static inline void list_add_tail(struct list_head *new, struct list_head *head)\r\n  79{\r\n  80        __list_add(new, head-&gt;prev, head);\r\n  81}<\/pre>\n<p>\u6ce8\u610f\uff0c\u8fd9\u91cc\u7684\u5f62\u53c2prev\u548cnext\u662f\u4e24\u4e2a\u8fde\u7eed\u7684\u7ed3\u70b9\u3002\u8fd9\u5176\u5b9e\u662f\u6570\u636e\u7ed3\u6784\u4e2d\u5f88\u666e\u901a\u7684\u53cc\u94fe\u8868\u5143\u7d20\u6dfb\u52a0\u95ee\u9898\uff0c\u5728\u6b64\u4e0d\u518d\u8d58\u8ff0\u3002\u4e0b\u9762\u7684\u56fe\u53ef\u4f9b\u53c2\u8003\uff0c\u56fe\u4e2d1\uff5e4\u5206\u522b\u5bf9\u5e94__list_add\u51fd\u6570\u7684\u56db\u6761\u8bed\u53e5\u3002<\/p>\n<p><a href=\"http:\/\/edsionte.com\/techblog\/archives\/1074\/screenshot\" rel=\"attachment wp-att-1092\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-1092\" title=\"Screenshot\" src=\"http:\/\/edsionte.com\/techblog\/wordpress\/wp-content\/uploads\/2010\/08\/Screenshot-300x155.png\" alt=\"\" width=\"300\" height=\"155\" srcset=\"http:\/\/edsionte.com\/techblog\/wordpress\/wp-content\/uploads\/2010\/08\/Screenshot-300x155.png 300w, http:\/\/edsionte.com\/techblog\/wordpress\/wp-content\/uploads\/2010\/08\/Screenshot.png 695w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\n3.\u5220\u9664\u5143\u7d20<\/p>\n<p>\u8fd9\u91cc\u53c8\u662f\u4e00\u4e2a\u8c03\u7528\u5173\u7cfb\uff0c__list_del\u51fd\u6570\u5177\u4f53\u7684\u8fc7\u7a0b\u5f88\u7b80\u5355\uff0c\u5206\u522b\u8ba9entry\u8282\u70b9\u7684\u524d\u540e\u4e24\u4e2a\u7ed3\u70b9\uff08prev\u548cnext\uff09\u201c\u8d8a\u7ea7\u201d\u6307\u5411\u5f7c\u6b64\u3002\u8bf7\u6ce8\u610f\u8fd9\u4e2a\u51fd\u6570\u7684\u540e\u4e24\u53e5\u8bdd\uff0c\u5b83\u5c5e\u4e8e\u4e0d\u5b89\u5168\u7684\u5220\u9664\u3002<\/p>\n<pre class=\"brush:c\"> 103static inline void list_del(struct list_head *entry)\r\n 104{\r\n 105        __list_del(entry-&gt;prev, entry-&gt;next);\r\n 106        entry-&gt;next = LIST_POISON1;\r\n 107        entry-&gt;prev = LIST_POISON2;\r\n 108}<\/pre>\n<p>\u60f3\u8981\u5b89\u5168\u7684\u5220\u9664\uff0c\u90a3\u4e48\u53ef\u4ee5\u8c03\u7528\u4e0b\u9762\u51fd\u6570\u3002\u8fd8\u8bb0\u5f97INIT_LIST_HEAD(entry)\u5417\uff0c\u5b83\u53ef\u4ee5\u4f7fentry\u8282\u70b9\u7684\u4e24\u4e2a\u6307\u9488\u6307\u5411\u81ea\u5df1\u3002<\/p>\n<pre class=\"brush:c\"> 140static inline void list_del_init(struct list_head *entry)\r\n 141{\r\n 142        __list_del(entry-&gt;prev, entry-&gt;next);\r\n 143        INIT_LIST_HEAD(entry);\r\n 144}<\/pre>\n<p>4.\u66ff\u6362\u5143\u7d20<\/p>\n<p>\u7528new\u7ed3\u70b9\u66ff\u6362old\u7ed3\u70b9\u540c\u6837\u5f88\u7b80\u5355\uff0c\u51e0\u4e4e\u662f\u5728old-&gt;prev\u548cold-&gt;next\u4e24\u7ed3\u70b9\u4e4b\u95f4\u63d2\u5165\u4e00\u4e2anew\u7ed3\u70b9\u3002\u753b\u56fe\u5373\u53ef\u7406\u89e3\u3002<\/p>\n<pre class=\"brush:c\">120static inline void list_replace(struct list_head *old,\r\n 121                                struct list_head *new)\r\n 122{\r\n 123        new-&gt;next = old-&gt;next;\r\n 124        new-&gt;next-&gt;prev = new;\r\n 125        new-&gt;prev = old-&gt;prev;\r\n 126        new-&gt;prev-&gt;next = new;\r\n 127}<\/pre>\n<p>\u540c\u6837\uff0c\u60f3\u8981\u5b89\u5168\u66ff\u6362\uff0c\u53ef\u4ee5\u8c03\u7528\uff1a<\/p>\n<pre class=\"brush:c\"> 129static inline void list_replace_init(struct list_head *old,\r\n 130                                        struct list_head *new)\r\n 131{\r\n 132        list_replace(old, new);\r\n 133        INIT_LIST_HEAD(old);\r\n 134}<\/pre>\n<p>5.\u79fb\u52a8\u5143\u7d20<\/p>\n<p>\u7406\u89e3\u4e86\u5220\u9664\u548c\u589e\u52a0\u7ed3\u70b9\uff0c\u90a3\u4e48\u5c06\u4e00\u4e2a\u8282\u70b9\u79fb\u52a8\u5230\u94fe\u8868\u4e2d\u53e6\u4e00\u4e2a\u4f4d\u7f6e\uff0c\u5176\u5b9e\u5c31\u5f88\u6e05\u6670\u4e86\u3002<span style=\"font-family: Consolas, Monaco, 'Courier New', Courier, monospace; line-height: 18px; font-size: 12px; white-space: pre;\">list_move\u51fd\u6570<span style=\"font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 19px; white-space: normal; font-size: 13px;\">\u6700\u7ec8\u8c03\u7528\u7684\u662f__list_add(list,head,head-&gt;next)\uff0c\u5b9e\u73b0\u5c06list\u79fb\u52a8\u5230\u5934\u7ed3\u70b9\u4e4b\u540e\uff1b\u800clist_move_tail\u51fd\u6570\u6700\u7ec8\u8c03\u7528__list_add_tail(list,head-&gt;prev,head)\uff0c\u5b9e\u73b0\u5c06list\u8282\u70b9\u79fb\u52a8\u5230\u94fe\u8868\u672b\u5c3e\u3002<\/span><\/span><\/p>\n<pre class=\"brush:c\"> 151static inline void list_move(struct list_head *list, struct list_head *head)\r\n 152{\r\n 153        __list_del(list-&gt;prev, list-&gt;next);\r\n 154        list_add(list, head);\r\n 155}\r\n 156\r\n\r\n 162static inline void list_move_tail(struct list_head *list,\r\n 163                                  struct list_head *head)\r\n 164{\r\n 165        __list_del(list-&gt;prev, list-&gt;next);\r\n 166        list_add_tail(list, head);\r\n 167}<\/pre>\n<p>6.\u6d4b\u8bd5\u51fd\u6570<\/p>\n<p>\u63a5\u4e0b\u6765\u7684\u51e0\u4e2a\u6d4b\u8bd5\u51fd\u6570\uff0c\u57fa\u672c\u4e0a\u662f\u201c\u4ee3\u7801\u5982\u5176\u540d\u201d\u3002<\/p>\n<p>list_is_last\u51fd\u6570\u662f\u6d4b\u8bd5list\u662f\u5426\u4e3a\u94fe\u8868head\u7684\u6700\u540e\u4e00\u4e2a\u8282\u70b9\u3002<\/p>\n<pre class=\"brush:c\"> 174static inline int list_is_last(const struct list_head *list,\r\n 175                                const struct list_head *head)\r\n 176{\r\n 177        return list-&gt;next == head;\r\n 178}<\/pre>\n<p>\u4e0b\u9762\u7684\u51fd\u6570\u662f\u6d4b\u8bd5head\u94fe\u8868\u662f\u5426\u4e3a\u7a7a\u94fe\u8868\u3002\u6ce8\u610f\u8fd9\u4e2alist_empty_careful\u51fd\u6570\uff0c\u4ed6\u6bd4list_empty\u51fd\u6570\u201c\u4ed4\u7ec6\u201d\u5728\u90a3\u91cc\u5462\uff1f\u524d\u8005\u53ea\u662f\u8ba4\u4e3a\u53ea\u8981\u4e00\u4e2a\u7ed3\u70b9\u7684next\u6307\u9488\u6307\u5411\u5934\u6307\u9488\u5c31\u7b97\u4e3a\u7a7a\uff0c\u4f46\u662f\u540e\u8005\u8fd8\u8981\u53bb\u68c0\u67e5\u5934\u8282\u70b9\u7684prev\u6307\u9488\u662f\u5426\u4e5f\u6307\u5411\u5934\u7ed3\u70b9\u3002\u53e6\u5916\uff0c\u8fd9\u79cd\u4ed4\u7ec6\u4e5f\u662f\u6709\u6761\u4ef6\u7684\uff0c\u53ea\u6709\u5728\u5220\u9664\u8282\u70b9\u65f6\u7528list_del_init()\uff0c\u624d\u80fd\u786e\u4fdd\u68c0\u6d4b\u6210\u529f\u3002<\/p>\n<pre class=\"brush:c\"> 184static inline int list_empty(const struct list_head *head)\r\n 185{\r\n 186        return head-&gt;next == head;\r\n 187}\r\n\r\n 202static inline int list_empty_careful(const struct list_head *head)\r\n 203{\r\n 204        struct list_head *next = head-&gt;next;\r\n 205        return (next == head) &amp;&amp; (next == head-&gt;prev);\r\n 206}<\/pre>\n<p>\u4e0b\u9762\u7684\u51fd\u6570\u662f\u6d4b\u8bd5head\u94fe\u8868\u662f\u5426\u53ea\u6709\u4e00\u4e2a\u7ed3\u70b9\uff1a\u8fd9\u4e2a\u94fe\u8868\u65e2\u4e0d\u80fd\u662f\u7a7a\u800c\u4e14head\u524d\u540e\u7684\u4e24\u4e2a\u7ed3\u70b9\u90fd\u5f97\u662f\u540c\u4e00\u4e2a\u7ed3\u70b9\u3002<\/p>\n<pre class=\"brush:c\">226static inline int list_is_singular(const struct list_head *head)\r\n227{\r\n228        return !list_empty(head) &amp;&amp; (head-&gt;next == head-&gt;prev);\r\n229}<\/pre>\n<p>7.\u5c06\u94fe\u8868\u5de6\u8f6c180\u5ea6<\/p>\n<p>\u6b63\u5982\u6ce8\u91ca\u8bf4\u660e\u7684\u90a3\u6837\uff0c\u6b64\u51fd\u6570\u4f1a\u5c06\u8fd9\u4e2a\u94fe\u8868\u4ee5head\u4e3a\u8f6c\u52a8\u70b9\uff0c\u5de6\u8f6c180\u5ea6\u3002\u6574\u4e2a\u8fc7\u7a0b\u5c31\u662f\u5c06head\u540e\u7684\u7ed3\u70b9\u4e0d\u65ad\u7684\u79fb\u52a8\u5230head\u7ed3\u70b9\u7684\u6700\u5de6\u7aef\u3002\u5982\u679c\u662f\u5355\u4e2a\u7ed3\u70b9\u90a3\u4e48\u8fd4\u56de\u771f\uff0c\u5426\u5219\u5047\u3002<\/p>\n<pre class=\"brush:c\">212static inline void list_rotate_left(struct list_head *head)\r\n213{\r\n214        struct list_head *first;\r\n215\r\n216        if (!list_empty(head)) {\r\n217                first = head-&gt;next;\r\n218                list_move_tail(first, head);\r\n219        }\r\n220}<\/pre>\n<p>\u4e0a\u8ff0\u51fd\u6570\u6bcf\u6b21\u90fd\u8c03\u7528 list_move_tail(first, head);\u5176\u5b9e\u6211\u4eec\u5c06\u5176\u5206\u89e3\u5230\u201c\u6700\u5c0f\u201d\uff0c\u90a3\u4e48\u8fd9\u4e2a\u51fd\u6570\u6bcf\u6b21\u6700\u7ec8\u8c03\u7528\u7684\u90fd\u662f\uff1a__list_del(first-&gt;prev,first-&gt;next);\u548c__list_add(list,head-&gt;prev,head);\u8fd9\u6837\u770b\u8d77\u6765\u5176\u5b9e\u5c31\u4e00\u76ee\u4e86\u7136\u4e86\u3002<\/p>\n<p>8.\u5c06\u94fe\u8868\u4e00\u5206\u4e3a\u4e8c<\/p>\n<p>\u8fd9\u4e2a\u51fd\u6570\u662f\u5c06head\u540e\u81f3entry\u4e4b\u95f4\uff08\u5305\u62ecentry\uff09\u7684\u6240\u6709\u7ed3\u70b9\u90fd\u201c\u5207\u5f00\u201d\uff0c\u8ba9\u4ed6\u4eec\u6210\u4e3a\u4e00\u4e2a\u4ee5list\u4e3a\u5934\u7ed3\u70b9\u7684\u65b0\u94fe\u8868\u3002\u6211\u4eec\u5148\u4ece\u5b8f\u89c2\u4e0a\u770b\uff0c\u5982\u679chead\u672c\u8eab\u662f\u4e00\u4e2a\u7a7a\u94fe\u8868\u5219\u5931\u8d25\uff1b\u5982\u679chead\u662f\u4e00\u4e2a\u5355\u7ed3\u70b9\u94fe\u8868\u800c\u4e14entry\u6240\u6307\u7684\u90a3\u4e2a\u7ed3\u70b9\u53c8\u4e0d\u518d\u8fd9\u4e2a\u94fe\u8868\u4e2d\uff0c\u4e5f\u5931\u8d25\uff1b\u5f53entry\u6070\u597d\u5c31\u662f\u5934\u7ed3\u70b9\uff0c\u90a3\u4e48\u76f4\u63a5\u521d\u59cb\u5316list\uff0c\u4e3a\u4ec0\u4e48\uff1f\u56e0\u4e3a\u6309\u7167\u521a\u624d\u6240\u8bf4\u7684\u5207\u5272\u89c4\u5219\uff0c\u4ecehead\u540e\u5230entry\u524d\u4e8b\u5b9e\u4e0a\u5c31\u662f\u7a7a\u7ed3\u70b9\u3002\u5982\u679c\u4e0a\u8ff0\u6761\u4ef6\u90fd\u4e0d\u7b26\u5408\uff0c\u90a3\u4e48\u5c31\u53ef\u4ee5\u653e\u5fc3\u7684\u201c\u5207\u5272\u201d\u4e86\u3002<\/p>\n<pre class=\"brush:c\">257static inline void list_cut_position(struct list_head *list,\r\n258                struct list_head *head, struct list_head *entry)\r\n259{\r\n260        if (list_empty(head))\r\n261                return;\r\n262        if (list_is_singular(head) &amp;&amp;\r\n263                (head-&gt;next != entry &amp;&amp; head != entry))\r\n264                return;\r\n265        if (entry == head)\r\n266                INIT_LIST_HEAD(list);\r\n267        else\r\n268                __list_cut_position(list, head, entry);\r\n269}<\/pre>\n<p>\u5177\u4f53\u5982\u4f55\u5207\u5272\uff0c\u8fd9\u91cc\u7684\u4ee3\u7801\u8c8c\u4f3c\u5f88\u9ebb\u70e6\uff0c\u53ef\u662f\u6211\u4eec\u753b\u51fa\u56fe\u540e\uff0c\u5c31\u201c\u4e00\u5207\u5c3d\u5728\u4e0d\u8a00\u4e2d\u201d\u4e86\u3002<\/p>\n<pre class=\"brush:c\">231static inline void __list_cut_position(struct list_head *list,\r\n232                struct list_head *head, struct list_head *entry)\r\n233{\r\n234        struct list_head *new_first = entry-&gt;next;\r\n235        list-&gt;next = head-&gt;next;\r\n236        list-&gt;next-&gt;prev = list;\r\n237        list-&gt;prev = entry;\r\n238        entry-&gt;next = list;\r\n239        head-&gt;next = new_first;\r\n240        new_first-&gt;prev = head;\r\n241}<\/pre>\n<p>\u56fe\u793a\uff1a<\/p>\n<p><a href=\"http:\/\/edsionte.com\/techblog\/archives\/1074\/screenshot-2\" rel=\"attachment wp-att-1093\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-1093\" title=\"Screenshot-2\" src=\"http:\/\/edsionte.com\/techblog\/wordpress\/wp-content\/uploads\/2010\/08\/Screenshot-2-300x138.png\" alt=\"\" width=\"300\" height=\"138\" srcset=\"http:\/\/edsionte.com\/techblog\/wordpress\/wp-content\/uploads\/2010\/08\/Screenshot-2-300x138.png 300w, http:\/\/edsionte.com\/techblog\/wordpress\/wp-content\/uploads\/2010\/08\/Screenshot-2.png 938w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Last Update\uff1a 8\/15 \u53cc\u94fe\u8868\u7684\u5e94\u7528\u5728\u5185\u6838\u4e2d\u968f\u5904\u53ef\u89c1\uff0clist.h\u5934\u6587\u4ef6\u96c6\u4e2d\u5b9a\u4e49\u4e86\u53cc\u94fe\u8868\uff08stru [&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],"class_list":["post-1074","post","type-post","status-publish","format-standard","hentry","category-linux","tag-kernel","tag-linux"],"views":33545,"_links":{"self":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts\/1074","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=1074"}],"version-history":[{"count":0,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts\/1074\/revisions"}],"wp:attachment":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/media?parent=1074"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/categories?post=1074"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/tags?post=1074"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}