Structure to pass parameters to Scheduler

This commit is contained in:
Adrien Bourmault 2021-06-11 11:39:42 +02:00
parent 0d796ff599
commit 7829fb1457
No known key found for this signature in database
GPG Key ID: 6EB408FE0ACEC664
4 changed files with 37 additions and 34 deletions

View File

@ -36,3 +36,12 @@ struct {
size_t size; size_t size;
int *space; int *space;
} typedef IntArray_t; } typedef IntArray_t;
struct {
BoolArray_t *globalPreemptionSpace;
IntArray_t *globalDrawingSpace;
IntArray_t *transitionsTree;
IntArray_t *arrowList;
int nmaxThread;
int nmaxCycles;
} typedef SchedulerParams_t;

View File

@ -23,8 +23,7 @@
#include "../include/base.h" #include "../include/base.h"
#endif #endif
pthread_t *SchedInit(BoolArray_t *globalPreemptionSpace, IntArray_t *transitionsTree, pthread_t *SchedInit(SchedulerParams_t *parameters);
IntArray_t *arrowList, int nmaxThread, int nmaxCycles);
int SchedWait(pthread_t *schedThread); int SchedWait(pthread_t *schedThread);

View File

@ -32,47 +32,43 @@
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
BoolArray_t *globalPreemptionSpace = NULL; //
IntArray_t *globalDrawingSpace = NULL; // Creating parameters structure for the Scheduler
IntArray_t *arrowList = NULL; //
IntArray_t *transitionsTree = NULL; SchedulerParams_t *parameters = NULL;
globalPreemptionSpace = (BoolArray_t*) malloc(sizeof(BoolArray_t)); parameters->globalPreemptionSpace = (BoolArray_t*) malloc(sizeof(BoolArray_t));
globalPreemptionSpace->space = (bool*) malloc(sizeof(bool)*SPACE_SIZE); parameters->globalPreemptionSpace->space = (bool*) malloc(sizeof(bool)*SPACE_SIZE);
globalPreemptionSpace->size = SPACE_SIZE; parameters->globalPreemptionSpace->size = SPACE_SIZE;
globalDrawingSpace = (IntArray_t*) malloc(sizeof(IntArray_t)); parameters->globalDrawingSpace = (IntArray_t*) malloc(sizeof(IntArray_t));
globalDrawingSpace->space = (int*) malloc(sizeof(int)*SPACE_SIZE); parameters->globalDrawingSpace->space = (int*) malloc(sizeof(int)*SPACE_SIZE);
globalDrawingSpace->size = SPACE_SIZE; parameters->globalDrawingSpace->size = SPACE_SIZE;
arrowList = (IntArray_t*) malloc(sizeof(IntArray_t)); parameters->arrowList = (IntArray_t*) malloc(sizeof(IntArray_t));
arrowList->space = (int*) malloc(sizeof(int)*ARROW_NUMBER); parameters->arrowList->space = (int*) malloc(sizeof(int)*ARROW_NUMBER);
arrowList->size = ARROW_NUMBER; parameters->arrowList->size = ARROW_NUMBER;
printf("globalPreemptionSpace: %p, size: %lu\n", globalPreemptionSpace, parameters->nmaxThread = MAX_THREAD;
globalDrawingSpace->size); parameters->nmaxCycles = MAX_CYCLES;
printf("globalDrawingSpace: %p, size: %lu\n", globalDrawingSpace,
globalDrawingSpace->size);
printf("arrowList: %p, size: %lu\n", arrowList, arrowList->size);
// //
// Calling the scheduler ! // Creating the Scheduler thread
// //
pthread_t *schedThread = SchedInit(globalPreemptionSpace, transitionsTree, arrowList, MAX_THREAD, pthread_t *schedThread = SchedInit(parameters);
MAX_CYCLES);
SchedWait(schedThread); SchedWait(schedThread);
SchedDestroy(schedThread); SchedDestroy(schedThread);
free(globalDrawingSpace->space); free(parameters->globalDrawingSpace->space);
free(globalDrawingSpace); free(parameters->globalDrawingSpace);
free(globalPreemptionSpace->space); free(parameters->globalPreemptionSpace->space);
free(globalPreemptionSpace); free(parameters->globalPreemptionSpace);
free(arrowList->space); free(parameters->arrowList->space);
free(arrowList); free(parameters->arrowList);
return 0; return 0;
} }

View File

@ -22,18 +22,17 @@
#include "../include/base.h" #include "../include/base.h"
#include "../include/localthread.h" #include "../include/localthread.h"
static void *GreatScheduler(void *vargp); static void *GreatScheduler(void *parameters);
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
// -------------------------------------------------------------------------- // // -------------------------------------------------------------------------- //
// Scheduler init function // // Scheduler init function //
// -------------------------------------------------------------------------- // // -------------------------------------------------------------------------- //
pthread_t *SchedInit(BoolArray_t *globalePreemptionSpace, IntArray_t *transitionsTree, pthread_t *SchedInit(SchedulerParams_t *parameters)
IntArray_t *arrowList, int nmaxThread, int nmaxCycles)
{ {
pthread_t *schedThread = (pthread_t*) malloc(sizeof(pthread_t)); pthread_t *schedThread = (pthread_t*) malloc(sizeof(pthread_t));
pthread_create(schedThread, NULL, GreatScheduler, NULL); pthread_create(schedThread, NULL, GreatScheduler, parameters);
return schedThread; return schedThread;
} }
@ -57,7 +56,7 @@ void SchedWait(pthread_t *schedThread)
// -------------------------------------------------------------------------- // // -------------------------------------------------------------------------- //
// Scheduler thread main function // // Scheduler thread main function //
// -------------------------------------------------------------------------- // // -------------------------------------------------------------------------- //
static void *GreatScheduler(void *vargp) static void *GreatScheduler(void *parameters)
{ {
sleep(1); sleep(1);
printf("Printing from thread \n"); printf("Printing from thread \n");