In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the "linux one-way circular list source code analysis" related knowledge, in the actual case of the operation process, many people will encounter such a dilemma, and then let the editor lead you to learn how to deal with these situations! I hope you can read it carefully and be able to achieve something!
Extern inline void add_wait_queue (struct wait_queue * * p, struct wait_queue * wait) {unsigned long flags
# ifdef DEBUG if (wait- > next) {unsigned long pc; _ _ asm__ _ volatile__ ("call 1f\ n"1:\ tpopl% 0": "= r" (pc)); printk ("add_wait_queue (x): wait- > next = x\ n", pc, (unsigned long) wait- > next);} # endif save_flags (flags); cli () / / the queue is empty, the header pointer points to the node to be inserted, and the next pointer of the last node points to its own if (! * p) {wait- > next = wait; * p = wait;} else {/ * insert the node after the first node to form an one-way circular linked list thanks to zym. When inserting the second node, it is inserted after the first node, then in the middle of the first second node, and then directly from the first third node, and so on * p points to the first node, (* p)-> next points to the next node of the first node, and when inserting the second node, the next node of the first node is itself. Wait- > next means that the next of the new node points to the next node of the first node, and (* p)-> next = wait; means that the next pointer of the first node points to the newly added node. The traditional head insertion method can only form a single linked list, not a loop, because the loop needs to take the next of the tail pointer to point to the first node, but with the change of the linked list, the tail node can not be found. P-> head-> null p-> head-> node1 next |-> p-> head-> node1 node2 |-> p-> head-> node1 node3 node2 next = wait; * p = wait } else {/ / head insertion method to form a unidirectional linked list wait- > next = (* p)-> next; (* p)-> next = wait; / / printf ("% d", wait- > next = = * p);}} int main () {struct wait_queue wait = {1, NULL} Struct wait_queue wait1 = {2, NULL}; struct wait_queue wait2 = {3, NULL}; struct wait_queue * head = NULL; add_wait_queue (& head, & wait); add_wait_queue (& head, & wait1); add_wait_queue (& head, & wait2); int c = 5 While (head- -) {printf ("% d", head- > task); head = head- > next;}} * / wait- > next = (* p)-> next; (* p)-> next = wait;} restore_flags (flags);}
Extern inline void remove_wait_queue (struct wait_queue * * p, struct wait_queue * wait) {unsigned long flags; struct wait_queue * tmp;#ifdef DEBUG unsigned long ok = 0 positional dif
Save_flags (flags); cli (); / / if the first node is deleted and there is only one node, the header pointer points to NULL if ((* p = = wait) & & # ifdef DEBUG (ok = 1) & & # endif ((* p = wait- > next) = = wait)) {* p = NULL } else {/ / starts traversing the one-way circular list from itself, finds the one that next points to itself, and then updates the pointer tmp = wait; while (tmp- > next! = wait) {tmp = tmp- > next;#ifdef DEBUG if (tmp = = * p) ok = 1 other circuldif} tmp- > next = wait- > next;} wait- > next = NULL; restore_flags (flags) # ifdef DEBUG if (! ok) {printk ("removed wait_queue not on list.\ n"); printk ("list = x, queue = x\ n", (unsigned long) p, (unsigned long) wait); _ _ asm__ ("call 1f\ N1:\ tpopl% 0": "= r" (ok)); printk ("eip = x\ n", ok) } # endif} "linux one-way cyclic list source code analysis" is introduced here, thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.