From 0298ffc3a1f095bcb4719a80ec2efd871d439954 Mon Sep 17 00:00:00 2001 From: sara Date: Tue, 6 Feb 2018 23:35:01 -0500 Subject: [PATCH] edge case fixes --- Asst1/util.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/Asst1/util.c b/Asst1/util.c index 5a35021..8e94327 100644 --- a/Asst1/util.c +++ b/Asst1/util.c @@ -73,18 +73,34 @@ threadNode* dequeue () threadQ * get_next_executable(int * curr) { + int * last; + //find first non empty threadQ threadQ * non_empty = _scan_non_empty(curr); + //save the location of the first non empty queue in case of edge cases + *last = *curr; + //if it's already maxed out its threshold, set threshold back to max and find next non empty if (non_empty -> threshold == 0) { non_empty -> threshold = MAXTHD - *curr; *curr += 1; } - - if (*curr == LEVELS) + non_empty = _scan_non_empty(curr); + //THIS IS FOR THE EDGE CASE THAT THERE WAS ONLY ONE NONEMPTY QUEUE, AND IT HAPPENED TO HAVE BEEN MAXED OUT + //if there are no other nonempty threadQs after the one we just had + if (non_empty == NULL) { - return NULL; + //look for another nonempty starting from the beginning + non_empty = _scan_non_empty(last); + //set the threshold back to max, dequeue normally + if (non_empty -> threshold == 0) + { + non_empty -> threshold = MAXTHD - *curr; + } } - non_empty = _scan_non_empty(curr); + if (non_empty == NULL) + { + return NULL; + } non_empty->threshold -= 1; return non_empty; }