From 7829fb1457878a998d7fec0e4289ff253f9abbf9 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Fri, 11 Jun 2021 11:39:42 +0200 Subject: [PATCH] Structure to pass parameters to Scheduler --- include/base.h | 9 ++++++++ include/scheduler.h | 3 +-- src/main.c | 50 +++++++++++++++++++++------------------------ src/scheduler.c | 9 ++++---- 4 files changed, 37 insertions(+), 34 deletions(-) diff --git a/include/base.h b/include/base.h index e40e356..cf3829b 100644 --- a/include/base.h +++ b/include/base.h @@ -36,3 +36,12 @@ struct { size_t size; int *space; } typedef IntArray_t; + +struct { + BoolArray_t *globalPreemptionSpace; + IntArray_t *globalDrawingSpace; + IntArray_t *transitionsTree; + IntArray_t *arrowList; + int nmaxThread; + int nmaxCycles; +} typedef SchedulerParams_t; diff --git a/include/scheduler.h b/include/scheduler.h index 8d3f488..b10a305 100644 --- a/include/scheduler.h +++ b/include/scheduler.h @@ -23,8 +23,7 @@ #include "../include/base.h" #endif -pthread_t *SchedInit(BoolArray_t *globalPreemptionSpace, IntArray_t *transitionsTree, - IntArray_t *arrowList, int nmaxThread, int nmaxCycles); +pthread_t *SchedInit(SchedulerParams_t *parameters); int SchedWait(pthread_t *schedThread); diff --git a/src/main.c b/src/main.c index 9f97911..a20a721 100644 --- a/src/main.c +++ b/src/main.c @@ -32,47 +32,43 @@ int main(int argc, char **argv) { - BoolArray_t *globalPreemptionSpace = NULL; - IntArray_t *globalDrawingSpace = NULL; - IntArray_t *arrowList = NULL; - IntArray_t *transitionsTree = NULL; + // + // Creating parameters structure for the Scheduler + // + SchedulerParams_t *parameters = NULL; - globalPreemptionSpace = (BoolArray_t*) malloc(sizeof(BoolArray_t)); - globalPreemptionSpace->space = (bool*) malloc(sizeof(bool)*SPACE_SIZE); - globalPreemptionSpace->size = SPACE_SIZE; + parameters->globalPreemptionSpace = (BoolArray_t*) malloc(sizeof(BoolArray_t)); + parameters->globalPreemptionSpace->space = (bool*) malloc(sizeof(bool)*SPACE_SIZE); + parameters->globalPreemptionSpace->size = SPACE_SIZE; - globalDrawingSpace = (IntArray_t*) malloc(sizeof(IntArray_t)); - globalDrawingSpace->space = (int*) malloc(sizeof(int)*SPACE_SIZE); - globalDrawingSpace->size = SPACE_SIZE; + parameters->globalDrawingSpace = (IntArray_t*) malloc(sizeof(IntArray_t)); + parameters->globalDrawingSpace->space = (int*) malloc(sizeof(int)*SPACE_SIZE); + parameters->globalDrawingSpace->size = SPACE_SIZE; - arrowList = (IntArray_t*) malloc(sizeof(IntArray_t)); - arrowList->space = (int*) malloc(sizeof(int)*ARROW_NUMBER); - arrowList->size = ARROW_NUMBER; + parameters->arrowList = (IntArray_t*) malloc(sizeof(IntArray_t)); + parameters->arrowList->space = (int*) malloc(sizeof(int)*ARROW_NUMBER); + parameters->arrowList->size = ARROW_NUMBER; - printf("globalPreemptionSpace: %p, size: %lu\n", globalPreemptionSpace, - globalDrawingSpace->size); - printf("globalDrawingSpace: %p, size: %lu\n", globalDrawingSpace, - globalDrawingSpace->size); - printf("arrowList: %p, size: %lu\n", arrowList, arrowList->size); + parameters->nmaxThread = MAX_THREAD; + parameters->nmaxCycles = MAX_CYCLES; // - // Calling the scheduler ! + // Creating the Scheduler thread // - pthread_t *schedThread = SchedInit(globalPreemptionSpace, transitionsTree, arrowList, MAX_THREAD, - MAX_CYCLES); + pthread_t *schedThread = SchedInit(parameters); SchedWait(schedThread); SchedDestroy(schedThread); - free(globalDrawingSpace->space); - free(globalDrawingSpace); + free(parameters->globalDrawingSpace->space); + free(parameters->globalDrawingSpace); - free(globalPreemptionSpace->space); - free(globalPreemptionSpace); + free(parameters->globalPreemptionSpace->space); + free(parameters->globalPreemptionSpace); - free(arrowList->space); - free(arrowList); + free(parameters->arrowList->space); + free(parameters->arrowList); return 0; } diff --git a/src/scheduler.c b/src/scheduler.c index f6d4bc8..2d0f3a9 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -22,18 +22,17 @@ #include "../include/base.h" #include "../include/localthread.h" -static void *GreatScheduler(void *vargp); +static void *GreatScheduler(void *parameters); /* -------------------------------------------------------------------------- */ // -------------------------------------------------------------------------- // // Scheduler init function // // -------------------------------------------------------------------------- // -pthread_t *SchedInit(BoolArray_t *globalePreemptionSpace, IntArray_t *transitionsTree, - IntArray_t *arrowList, int nmaxThread, int nmaxCycles) +pthread_t *SchedInit(SchedulerParams_t *parameters) { pthread_t *schedThread = (pthread_t*) malloc(sizeof(pthread_t)); - pthread_create(schedThread, NULL, GreatScheduler, NULL); + pthread_create(schedThread, NULL, GreatScheduler, parameters); return schedThread; } @@ -57,7 +56,7 @@ void SchedWait(pthread_t *schedThread) // -------------------------------------------------------------------------- // // Scheduler thread main function // // -------------------------------------------------------------------------- // -static void *GreatScheduler(void *vargp) +static void *GreatScheduler(void *parameters) { sleep(1); printf("Printing from thread \n");