More 'objective' definitions
This commit is contained in:
parent
02c42045c2
commit
9248f8176b
|
@ -54,11 +54,12 @@ struct {
|
|||
int nmaxThread;
|
||||
int nmaxCycles;
|
||||
pthread_t *id;
|
||||
} typedef SchedulerParams_t;
|
||||
bool stopped;
|
||||
} typedef Scheduler_t;
|
||||
|
||||
struct {
|
||||
pthread_t *id;
|
||||
} typedef WorkerParams_t;
|
||||
} typedef Worker_t;
|
||||
|
||||
//
|
||||
// Local threads
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
// -------------------------------------------------------------------------- //
|
||||
// Worker init function //
|
||||
// -------------------------------------------------------------------------- //
|
||||
pthread_t *WorkerInit(SchedulerParams_t *parameters);
|
||||
pthread_t *WorkerInit(Worker_t *parameters);
|
||||
|
||||
// -------------------------------------------------------------------------- //
|
||||
// Worker destructor function //
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
// -------------------------------------------------------------------------- //
|
||||
// Scheduler init function //
|
||||
// -------------------------------------------------------------------------- //
|
||||
pthread_t *SchedInit(SchedulerParams_t *parameters);
|
||||
pthread_t *SchedInit(Scheduler_t *parameters);
|
||||
|
||||
// -------------------------------------------------------------------------- //
|
||||
// Scheduler destructor function //
|
||||
|
|
|
@ -28,7 +28,7 @@ static void *LittleWorker(void *parameters);
|
|||
// -------------------------------------------------------------------------- //
|
||||
// Scheduler init function //
|
||||
// -------------------------------------------------------------------------- //
|
||||
pthread_t *WorkerInit(SchedulerParams_t *parameters)
|
||||
pthread_t *WorkerInit(Scheduler_t *parameters)
|
||||
{
|
||||
parameters->id = (pthread_t*) malloc(sizeof(pthread_t));
|
||||
pthread_create(parameters->id, NULL, LittleWorker, parameters);
|
||||
|
@ -40,7 +40,7 @@ pthread_t *WorkerInit(SchedulerParams_t *parameters)
|
|||
// -------------------------------------------------------------------------- //
|
||||
static void *LittleWorker(void *params)
|
||||
{
|
||||
WorkerParams_t *parameters = (WorkerParams_t*) params;
|
||||
Worker_t *parameters = (Worker_t*) params;
|
||||
int a = 4;
|
||||
|
||||
for (int i = 0; i < 45000; i++) {
|
||||
|
|
66
src/main.c
66
src/main.c
|
@ -33,14 +33,14 @@ void SchedulerCrashTest(void)
|
|||
{
|
||||
const int maxthread = 16;
|
||||
|
||||
SchedulerParams_t *parameters =
|
||||
(SchedulerParams_t*) calloc(1, sizeof(SchedulerParams_t));
|
||||
Scheduler_t *scheduler0 =
|
||||
(Scheduler_t*) calloc(1, sizeof(Scheduler_t));
|
||||
|
||||
pthread_t **schedThread =
|
||||
(pthread_t**) malloc(sizeof(pthread_t*) * maxthread);
|
||||
|
||||
for (int i=0; i < maxthread; i++) {
|
||||
schedThread[i] = SchedInit(parameters);
|
||||
schedThread[i] = SchedInit(scheduler0);
|
||||
}
|
||||
|
||||
for (int i=0; i < maxthread; i++) {
|
||||
|
@ -48,61 +48,65 @@ void SchedulerCrashTest(void)
|
|||
SchedDestroy(schedThread[i]);
|
||||
}
|
||||
|
||||
free(parameters);
|
||||
free(scheduler0);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
time_t t;
|
||||
Scheduler_t *scheduler0;
|
||||
|
||||
// Go!
|
||||
printLog("Starting gem-graph-server...\n");
|
||||
|
||||
time_t t = time(&t);
|
||||
//
|
||||
// random generator
|
||||
//
|
||||
t = time(&t);
|
||||
srand((unsigned) t);
|
||||
|
||||
//
|
||||
// Creating parameters structure for the Scheduler
|
||||
// Creating structure for the Scheduler
|
||||
//
|
||||
SchedulerParams_t *parameters =
|
||||
(SchedulerParams_t*) malloc(sizeof(SchedulerParams_t));
|
||||
scheduler0 = (Scheduler_t*) malloc(sizeof(Scheduler_t));
|
||||
|
||||
parameters->globalPreemptionSpace =
|
||||
scheduler0->globalPreemptionSpace =
|
||||
(BoolArray_t*) malloc(sizeof(BoolArray_t));
|
||||
parameters->globalPreemptionSpace->space =
|
||||
scheduler0->globalPreemptionSpace->space =
|
||||
(bool*) malloc(sizeof(bool)*SPACE_SIZE);
|
||||
parameters->globalPreemptionSpace->size = SPACE_SIZE;
|
||||
scheduler0->globalPreemptionSpace->size = SPACE_SIZE;
|
||||
|
||||
parameters->globalDrawingSpace = (IntArray_t*) malloc(sizeof(IntArray_t));
|
||||
parameters->globalDrawingSpace->space =
|
||||
scheduler0->globalDrawingSpace = (IntArray_t*) malloc(sizeof(IntArray_t));
|
||||
scheduler0->globalDrawingSpace->space =
|
||||
(int*) malloc(sizeof(int)*SPACE_SIZE);
|
||||
parameters->globalDrawingSpace->size = SPACE_SIZE;
|
||||
scheduler0->globalDrawingSpace->size = SPACE_SIZE;
|
||||
|
||||
parameters->arrowList = (IntArray_t*) malloc(sizeof(IntArray_t));
|
||||
parameters->arrowList->space = (int*) malloc(sizeof(int)*ARROW_NUMBER);
|
||||
parameters->arrowList->size = ARROW_NUMBER;
|
||||
scheduler0->arrowList = (IntArray_t*) malloc(sizeof(IntArray_t));
|
||||
scheduler0->arrowList->space = (int*) malloc(sizeof(int)*ARROW_NUMBER);
|
||||
scheduler0->arrowList->size = ARROW_NUMBER;
|
||||
|
||||
parameters->nmaxThread = MAX_THREAD;
|
||||
parameters->nmaxCycles = MAX_CYCLES;
|
||||
scheduler0->nmaxThread = MAX_THREAD;
|
||||
scheduler0->nmaxCycles = MAX_CYCLES;
|
||||
|
||||
//
|
||||
// Creating the Scheduler thread
|
||||
//
|
||||
pthread_t *schedThread = SchedInit(parameters);
|
||||
SchedInit(scheduler0);
|
||||
|
||||
SchedWait(schedThread);
|
||||
SchedWait(scheduler0->id);
|
||||
|
||||
SchedDestroy(schedThread);
|
||||
SchedDestroy(scheduler0->id);
|
||||
|
||||
free(parameters->globalDrawingSpace->space);
|
||||
free(parameters->globalDrawingSpace);
|
||||
free(scheduler0->globalDrawingSpace->space);
|
||||
free(scheduler0->globalDrawingSpace);
|
||||
|
||||
free(parameters->globalPreemptionSpace->space);
|
||||
free(parameters->globalPreemptionSpace);
|
||||
free(scheduler0->globalPreemptionSpace->space);
|
||||
free(scheduler0->globalPreemptionSpace);
|
||||
|
||||
free(parameters->arrowList->space);
|
||||
free(parameters->arrowList);
|
||||
free(scheduler0->arrowList->space);
|
||||
free(scheduler0->arrowList);
|
||||
|
||||
free(parameters);
|
||||
|
||||
//SchedulerCrashTest();
|
||||
free(scheduler0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ static void *GreatScheduler(void *parameters);
|
|||
// -------------------------------------------------------------------------- //
|
||||
// Scheduler init function //
|
||||
// -------------------------------------------------------------------------- //
|
||||
pthread_t *SchedInit(SchedulerParams_t *parameters)
|
||||
pthread_t *SchedInit(Scheduler_t *parameters)
|
||||
{
|
||||
parameters->id = (pthread_t*) malloc(sizeof(pthread_t));
|
||||
pthread_create(parameters->id, NULL, GreatScheduler, parameters);
|
||||
|
@ -74,7 +74,7 @@ static inline void centerRemove(Center_t *oldCenter)
|
|||
}
|
||||
|
||||
// -------------------------------------------------------------------------- //
|
||||
// Scheduler thread main function //
|
||||
// Scheduler area finder function //
|
||||
// -------------------------------------------------------------------------- //
|
||||
static Center_t *findWorkArea(Center_t *centerList, int ruleRadius, size_t spaceSize)
|
||||
{
|
||||
|
@ -102,8 +102,8 @@ static Center_t *findWorkArea(Center_t *centerList, int ruleRadius, size_t space
|
|||
static void *GreatScheduler(void *params)
|
||||
{
|
||||
// récupération des paramètres et annonce
|
||||
SchedulerParams_t *parameters = (SchedulerParams_t*) params;
|
||||
printLog("Scheduler id %lu: Bonjour I'm the boss !\n", *(parameters->id));
|
||||
Scheduler_t *args = (Scheduler_t*) params;
|
||||
printLog("Scheduler id %lu: Bonjour I'm the boss !\n", *(args->id));
|
||||
|
||||
int ncpu = get_nprocs();
|
||||
printLog("%d CPUs available.\n", ncpu);
|
||||
|
@ -116,7 +116,7 @@ static void *GreatScheduler(void *params)
|
|||
Center_t *workArea;
|
||||
int i = 0;
|
||||
|
||||
while (1) {
|
||||
while (!args->stopped) {
|
||||
while ((workArea = findWorkArea(centersList, 4, 30))) {
|
||||
i++;
|
||||
centerAdd(centersList, workArea);
|
||||
|
|
Loading…
Reference in New Issue