diff --git a/mxqd.c b/mxqd.c index 36fc0230..50ecc643 100644 --- a/mxqd.c +++ b/mxqd.c @@ -1491,6 +1491,23 @@ static int could_potentially_start_job_for_user(struct mxq_user_list *user) { return 0; } +static void move_user_to_end(struct mxq_server *server, struct mxq_user_list *user) { + struct mxq_user_list **ptr; + + if (!user->next) + return; + + ptr = &server->users; + while (*ptr != user) + ptr = &(*ptr)->next; + *ptr = user->next; + ptr = &(user->next->next); + while (*ptr) + ptr = &(*ptr)->next; + *ptr = user; + user->next = NULL; +} + long start_user_with_least_running_global_slot_count(struct mxq_server *server) { struct mxq_user_list *ulist; @@ -1524,8 +1541,12 @@ long start_user_with_least_running_global_slot_count(struct mxq_server *server) return -1; slots_started = start_user(ulist, slots_free, df_scratch); - if (slots_started) + if (slots_started) { + /* move user to end of list so that we get a round-robin with with + * other users which sort to the same precedence. */ + move_user_to_end(server, ulist); return slots_started; + } if (waiting) continue;