Threaded !

This commit is contained in:
Adrien Bourmault 2021-06-09 14:40:23 +02:00
parent e35b4b3725
commit 10ab0d01cd
No known key found for this signature in database
GPG Key ID: 6EB408FE0ACEC664
6 changed files with 126 additions and 15 deletions

View File

@ -1,5 +1,5 @@
//=-------------------------------------------------------------------------=//
// Main //
// base definition //
// //
// Copyright © 2021 The Gem-graph Project //
// //
@ -20,6 +20,12 @@
//=-------------------------------------------------------------------------=//
#include <stdbool.h>
#include <pthread.h>
#include <unistd.h>
#include <stdio.h>
#include <malloc.h>
#define BASE_H
struct {
size_t size;

View File

@ -0,0 +1,24 @@
//=-------------------------------------------------------------------------=//
// Scheduler definition //
// //
// Copyright © 2021 The Gem-graph Project //
// //
// This file is part of gem-graph. //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU Affero General Public License as //
// published by the Free Software Foundation, either version 3 of the //
// License, or (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU Affero General Public License for more details. //
// //
// You should have received a copy of the GNU Affero General Public License //
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#ifndef BASE_H
#include "../include/base.h"
#endif

View File

@ -0,0 +1,29 @@
//=-------------------------------------------------------------------------=//
// Scheduler definition //
// //
// Copyright © 2021 The Gem-graph Project //
// //
// This file is part of gem-graph. //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU Affero General Public License as //
// published by the Free Software Foundation, either version 3 of the //
// License, or (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU Affero General Public License for more details. //
// //
// You should have received a copy of the GNU Affero General Public License //
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#ifndef BASE_H
#include "../include/base.h"
#endif
pthread_t *SchedInit(BoolArray_t *globalPreemptionSpace, IntArray_t *transitionsTree,
IntArray_t *arrowList, int nmaxThread, int nmaxCycles);
int SchedLaunch(pthread_t *schedThread);

View File

@ -0,0 +1,24 @@
//=-------------------------------------------------------------------------=//
// Server definition //
// //
// Copyright © 2021 The Gem-graph Project //
// //
// This file is part of gem-graph. //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU Affero General Public License as //
// published by the Free Software Foundation, either version 3 of the //
// License, or (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU Affero General Public License for more details. //
// //
// You should have received a copy of the GNU Affero General Public License //
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#ifndef BASE_H
#include "../include/base.h"
#endif

View File

@ -19,10 +19,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#include <pthread.h>
#include <stdio.h>
#include <malloc.h>
#include "../include/types.h"
#include "../include/base.h"
#include "../include/server.h"
#include "../include/scheduler.h"
@ -38,7 +35,7 @@ int main(int argc, char **argv)
BoolArray_t *globalPreemptionSpace = NULL;
IntArray_t *globalDrawingSpace = NULL;
IntArray_t *arrowList = NULL;
//IntArray_t *transitionTree = NULL;
IntArray_t *transitionsTree = NULL;
globalPreemptionSpace = (BoolArray_t*) malloc(sizeof(BoolArray_t));
globalPreemptionSpace->space = (bool*) malloc(sizeof(bool)*SPACE_SIZE);
@ -52,16 +49,28 @@ int main(int argc, char **argv)
arrowList->space = (int*) malloc(sizeof(int)*ARROW_NUMBER);
arrowList->size = ARROW_NUMBER;
printf("globalPreemptionSpace: %p, size: %lu\n", globalPreemptionSpace, globalDrawingSpace->size);
printf("globalDrawingSpace: %p, size: %lu\n", globalDrawingSpace, globalDrawingSpace->size);
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);
//
// Calling the scheduler !
//
pthread_t *schedThread = SchedInit(globalPreemptionSpace, transitionsTree, arrowList, MAX_THREAD,
MAX_CYCLES);
int res = SchedLaunch(schedThread);
free(globalDrawingSpace->space);
free(globalDrawingSpace);
free(globalPreemptionSpace->space);
free(globalPreemptionSpace);
free(arrowList->space);
free(arrowList);
return 0;
return res;
}

View File

@ -19,14 +19,33 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#include <pthread.h>
#include <stdio.h>
#include <malloc.h>
#include "../include/types.h"
#include "../include/base.h"
#include "../include/localthread.h"
int SchedInit(BoolArray_t *globalePreemptionSpace, IntArray_t *transitionsTree,
static void *GreatScheduler(void *vargp);
/* -------------------------------------------------------------------------- */
// -------------------------------------------------------------------------- //
// Scheduler init function //
// -------------------------------------------------------------------------- //
pthread_t *SchedInit(BoolArray_t *globalePreemptionSpace, IntArray_t *transitionsTree,
IntArray_t *arrowList, int nmaxThread, int nmaxCycles)
{
pthread_t *schedThread = (pthread_t*) malloc(sizeof(pthread_t));
pthread_create(schedThread, NULL, GreatScheduler, NULL);
return schedThread;
}
int SchedLaunch(pthread_t *schedThread)
{
pthread_join(*schedThread, NULL);
return 0;
}
static void *GreatScheduler(void *vargp)
{
sleep(1);
printf("Printing from thread \n");
return NULL;
}