Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
mxqd_control: Use generic sort function to sort users
No functional change.
  • Loading branch information
donald committed Jul 4, 2017
1 parent 8496f6a commit c956da7
Showing 1 changed file with 14 additions and 45 deletions.
59 changes: 14 additions & 45 deletions mxqd_control.c
Expand Up @@ -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);
}

0 comments on commit c956da7

Please sign in to comment.