diff --git a/mxqd_control.c b/mxqd_control.c index 419d6bfb..7a68d564 100644 --- a/mxqd_control.c +++ b/mxqd_control.c @@ -519,52 +519,21 @@ int server_remove_orphaned_groups(struct mxq_server *server) return cnt; } -void server_sort_users_by_running_global_slot_count(struct mxq_server *server) +static int cmp_users_by_global_running_slots(struct mxq_user_list *u1,struct mxq_user_list *u2) { - struct mxq_user_list *ulist; - struct mxq_user_list *unext; - struct mxq_user_list *uprev; - struct mxq_user_list *uroot; - struct mxq_user_list *current; - - assert(server); - - if (!server->user_cnt) - return; - - for (ulist = server->users, uroot = NULL; ulist; ulist = unext) { - unext = ulist->next; - - ulist->next = NULL; - - if (!uroot) { - uroot = ulist; - continue; - } - - for (current = uroot, uprev = NULL; (current || uprev); uprev = current, current = current->next) { - if (!current) { - uprev->next = ulist; - break; - } - if (ulist->global_slots_running > current->global_slots_running) { - continue; - } - if (ulist->global_slots_running == current->global_slots_running - && ulist->global_threads_running > current->global_threads_running) { - continue; - } - - ulist->next = current; + return + u1->global_slots_running > u2->global_slots_running ? 1 + : u1->global_slots_running < u2->global_slots_running ? -1 + : 0; +} - if (!uprev) { - uroot = ulist; - } else { - uprev->next = ulist; - } - break; - } - } +static struct mxq_user_list **get_users_nextptr(struct mxq_user_list *u) +{ + return &u->next; +} - server->users = uroot; +void server_sort_users_by_running_global_slot_count(struct mxq_server *server) +{ + assert(server); + mx_sort_linked_list(&server->users,cmp_users_by_global_running_slots,get_users_nextptr); }