From 10ab0d01cd9432cd1d4f5499b707440d53d672fd Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Wed, 9 Jun 2021 14:40:23 +0200 Subject: [PATCH] Threaded ! --- include/{types.h => base.h} | 8 +++++++- include/localthread.h | 24 ++++++++++++++++++++++++ include/scheduler.h | 29 +++++++++++++++++++++++++++++ include/server.h | 24 ++++++++++++++++++++++++ src/main.c | 25 +++++++++++++++++-------- src/scheduler.c | 31 +++++++++++++++++++++++++------ 6 files changed, 126 insertions(+), 15 deletions(-) rename include/{types.h => base.h} (90%) diff --git a/include/types.h b/include/base.h similarity index 90% rename from include/types.h rename to include/base.h index 960b71d..e40e356 100644 --- a/include/types.h +++ b/include/base.h @@ -1,5 +1,5 @@ //=-------------------------------------------------------------------------=// -// Main // +// base definition // // // // Copyright © 2021 The Gem-graph Project // // // @@ -20,6 +20,12 @@ //=-------------------------------------------------------------------------=// #include +#include +#include +#include +#include + +#define BASE_H struct { size_t size; diff --git a/include/localthread.h b/include/localthread.h index e69de29..fa36ae8 100644 --- a/include/localthread.h +++ b/include/localthread.h @@ -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 . // +//=-------------------------------------------------------------------------=// + +#ifndef BASE_H + #include "../include/base.h" +#endif diff --git a/include/scheduler.h b/include/scheduler.h index e69de29..27a43ed 100644 --- a/include/scheduler.h +++ b/include/scheduler.h @@ -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 . // +//=-------------------------------------------------------------------------=// + +#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); diff --git a/include/server.h b/include/server.h index e69de29..c36c3e8 100644 --- a/include/server.h +++ b/include/server.h @@ -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 . // +//=-------------------------------------------------------------------------=// + +#ifndef BASE_H + #include "../include/base.h" +#endif diff --git a/src/main.c b/src/main.c index 9aff640..79eee01 100644 --- a/src/main.c +++ b/src/main.c @@ -19,10 +19,7 @@ // along with this program. If not, see . // //=-------------------------------------------------------------------------=// -#include -#include -#include -#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; } diff --git a/src/scheduler.c b/src/scheduler.c index 784221b..975047d 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -19,14 +19,33 @@ // along with this program. If not, see . // //=-------------------------------------------------------------------------=// -#include -#include -#include -#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) { - return 0; + 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; }