Structure to pass parameters to Scheduler
This commit is contained in:
parent
0d796ff599
commit
7829fb1457
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
50
src/main.c
50
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;
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Reference in New Issue