diff --git a/include/base.h b/include/base.h index 9412f15..41d308b 100644 --- a/include/base.h +++ b/include/base.h @@ -25,6 +25,7 @@ #include #include #include +#include #define BASE_H diff --git a/src/main.c b/src/main.c index 154547e..55c0d6b 100644 --- a/src/main.c +++ b/src/main.c @@ -55,6 +55,9 @@ int main(int argc, char **argv) { printLog("Starting gem-graph-server...\n"); + time_t t = time(&t); + srand((unsigned) t); + // // Creating parameters structure for the Scheduler // diff --git a/src/scheduler.c b/src/scheduler.c index a0f5e43..3da3c45 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -23,7 +23,6 @@ #include "../include/localworker.h" #include -#include static void *GreatScheduler(void *parameters); @@ -49,10 +48,8 @@ static inline void centerAssign(Center_t *center, int x, int y, int z) center->z = z; } -static inline Center_t *centerAdd(Center_t *anyCenter) +static inline Center_t *centerAdd(Center_t *anyCenter, Center_t *newCenter) { - Center_t *newCenter = (Center_t*) malloc(sizeof(Center_t)); - Center_t *temp = anyCenter->next; anyCenter->next = newCenter; newCenter->next = temp; @@ -76,6 +73,29 @@ static inline void centerRemove(Center_t *oldCenter) free(oldCenter); } +// -------------------------------------------------------------------------- // +// Scheduler thread main function // +// -------------------------------------------------------------------------- // +static Center_t *findWorkArea(Center_t *centerList, int ruleRadius, size_t spaceSize) +{ + Center_t *myCenter = (Center_t*) malloc(sizeof(Center_t)); + centerAssign(myCenter, rand() % spaceSize, 0, 0); /* Je suis né quelque part.(ou pas !).*/ + + while (centerList != NULL){ + //printLog("Center : %d\n", centerList->x); + if (abs(myCenter->x - centerList->x) < ruleRadius){ + printLog("FAIL: no work area available at %d\n", myCenter->x); + free(myCenter); + return NULL; + } + centerList = centerList->next; + } + + printLog("SUCCESS ! at %d: < I've found a center.\n", myCenter->x); + + return myCenter; +} + // -------------------------------------------------------------------------- // // Scheduler thread main function // // -------------------------------------------------------------------------- // @@ -93,29 +113,16 @@ static void *GreatScheduler(void *params) centerAssign(centersList, -1, -1, -1); - return NULL; -} + Center_t *workArea; + int i = 0; -// -------------------------------------------------------------------------- // -// Scheduler thread main function // -// -------------------------------------------------------------------------- // -static Center_t *findWorkArea(Center_t *centerList, int ruleRadius) -{ - Center_t *myCenter = (Center_t*) malloc(sizeof(Center_t)); - centerAssign(myCenter, 10, 0, 0); /* Je suis né quelque part.(ou pas !).*/ - - while (centerList != NULL){ - if (abs(myCenter->x - centerList->x) < ruleRadius){ - printLog("FAIL: no work area available at %d\n", myCenter->x); - free(myCenter); - return NULL; + while (1) { + while ((workArea = findWorkArea(centersList, 4, 30))) { + i++; + centerAdd(centersList, workArea); } - centerList = centerList->next; + printLog("New centers : %d\n", i); } - printLog("SUCCESS ! at %d: < I've find a center.\n", myCenter->x); - - return myCenter; + return NULL; } - -