diff --git a/supervisor.c b/supervisor.c index 7d0369a..385acc7 100644 --- a/supervisor.c +++ b/supervisor.c @@ -6,6 +6,7 @@ */ #include "common.h" +#include static const char *pname; @@ -67,7 +68,7 @@ void initCircBuf() } for (int i = 0; i < MAX_ITEMS; i++) { - bestSolution[i] = -1; + bestSolution[i] = INT_MAX; } return; } @@ -107,20 +108,24 @@ void getSolution(sem_t *sUsedSpace, sem_t *sFreeSpace) int newSolutionLength = 0; // Compute length of current bestSolution - if (bestSolution[0] != -1) { + if ((bestSolution[0] != -1) && (bestSolution[0] != INT_MAX)) { for (int i = 0; i < MAX_ITEMS; i++) { if (bestSolution[i] == -1) { bestSolutionLength = i; break; } } + } else if (bestSolution[0] == INT_MAX) { + bestSolutionLength = 17; } // Compute length of newSolution - for (int i = 0; i < MAX_ITEMS; i++) { - if ((solution[i] == -1) && (i != 0)) { - newSolutionLength = i+1; - break; + if (solution[0] != -1) { + for (int i = 0; i < MAX_ITEMS; i++) { + if (solution[i] == -1) { + newSolutionLength = i; + break; + } } }