nuclear@1: #include nuclear@1: #include "wsys.h" nuclear@1: nuclear@1: struct wsys_module *wslist; nuclear@1: int wscount; nuclear@1: nuclear@1: int sgl_register_module(struct wsys_module *ws) nuclear@1: { nuclear@1: ws->next = wslist; nuclear@1: wslist = ws; nuclear@1: wscount++; nuclear@1: return 0; nuclear@1: } nuclear@1: nuclear@1: #define APPEND(node) \ nuclear@1: do { \ nuclear@1: if(!res) { \ nuclear@1: res = tail = node; \ nuclear@1: } else { \ nuclear@1: tail->next = (node); \ nuclear@1: tail = (node); \ nuclear@1: } \ nuclear@1: (node) = (node)->next; \ nuclear@1: tail->next = 0; \ nuclear@1: } while(0) nuclear@1: nuclear@1: static struct wsys_module *merge(struct wsys_module *list1, struct wsys_module *list2) nuclear@1: { nuclear@1: struct wsys_module *res, *tail; nuclear@1: nuclear@1: res = tail = 0; nuclear@1: nuclear@1: while(list1 || list2) { nuclear@1: if(list1 && list2) { nuclear@1: if(list1->prio <= list2->prio) { nuclear@1: APPEND(list1); nuclear@1: } else { nuclear@1: APPEND(list2); nuclear@1: } nuclear@1: } else if(list1) { nuclear@1: APPEND(list1); nuclear@1: } else { nuclear@1: APPEND(list2); nuclear@1: } nuclear@1: } nuclear@1: return res; nuclear@1: } nuclear@1: nuclear@1: static struct wsys_module *msort(struct wsys_module *list, int count) nuclear@1: { nuclear@1: int i, mid = count / 2; nuclear@1: struct wsys_module *prev, *list2 = list; nuclear@1: nuclear@1: if(!list->next) { nuclear@1: return list; nuclear@1: } nuclear@1: for(i=0; inext; nuclear@1: } nuclear@1: prev->next = 0; nuclear@1: nuclear@1: list = msort(list, mid); nuclear@1: list2 = msort(list2, count - mid); nuclear@1: return merge(list, list2); nuclear@1: }