Add comments to fork() logic for readibility
[notion/jeffpc.git] / ioncore / llist.c
blobb47eef2d43322d98a8bb75ae052efa25237276e7
1 /*
2 * ion/ioncore/llist.c
4 * Copyright (c) Tuomo Valkonen 1999-2009.
6 * See the included file LICENSE for details.
7 */
9 #include "common.h"
10 #include "llist.h"
11 #include "activity.h"
14 /*{{{ WMPlex numbered/mut.ex. list stuff */
17 void llist_iter_init(WLListIterTmp *tmp, WLListNode *llist)
19 *tmp=llist;
23 WLListNode *llist_iter(WLListIterTmp *tmp)
25 WLListNode *mgd=*tmp;
26 if(mgd!=NULL)
27 *tmp=mgd->next;
28 return mgd;
32 WRegion *llist_iter_regions(WLListIterTmp *tmp)
34 WLListNode *lnode=llist_iter(tmp);
35 return (lnode==NULL ? NULL : lnode->st->reg);
39 WLListNode *llist_nth_node(WLListNode *list, uint n)
41 WLListIterTmp tmp;
42 llist_iter_init(&tmp, list);
43 return (WLListNode*)iterable_nth(n, (VoidIterator*)llist_iter, &tmp);
47 void llist_link_after(WLListNode **list,
48 WLListNode *after, WLListNode *node)
50 if(after!=NULL){
51 LINK_ITEM_AFTER(*list, after, node, next, prev);
52 }else{
53 LINK_ITEM_FIRST(*list, node, next, prev);
58 void llist_link_last(WLListNode **list, WLListNode *node)
60 LINK_ITEM_LAST(*list, node, next, prev);
64 WLListNode *llist_index_to_after(WLListNode *list,
65 WLListNode *current,
66 int index)
68 if(index==LLIST_INDEX_AFTER_CURRENT_ACT){
69 WLListNode *after=current;
70 while(after!=NULL){
71 WLListNode *nxt=after->next;
72 if(nxt==NULL || nxt->st==NULL || nxt->st->reg==NULL)
73 break;
74 if(!region_is_activity_r(nxt->st->reg))
75 break;
76 after=nxt;
78 return after;
79 }else if(index==LLIST_INDEX_AFTER_CURRENT){
80 return current;
81 }else if(index<0){
82 return (list!=NULL ? list->prev : NULL);
83 }else if(index==0){
84 return NULL;
85 }else{ /* index>0 */
86 return llist_nth_node(list, index-1);
91 void llist_unlink(WLListNode **list, WLListNode *node)
93 UNLINK_ITEM(*list, node, next, prev);
97 /*}}}*/