Threaded !
This commit is contained in:
parent
e35b4b3725
commit
10ab0d01cd
|
@ -1,5 +1,5 @@
|
||||||
//=-------------------------------------------------------------------------=//
|
//=-------------------------------------------------------------------------=//
|
||||||
// Main //
|
// base definition //
|
||||||
// //
|
// //
|
||||||
// Copyright © 2021 The Gem-graph Project //
|
// Copyright © 2021 The Gem-graph Project //
|
||||||
// //
|
// //
|
||||||
|
@ -20,6 +20,12 @@
|
||||||
//=-------------------------------------------------------------------------=//
|
//=-------------------------------------------------------------------------=//
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <malloc.h>
|
||||||
|
|
||||||
|
#define BASE_H
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
size_t size;
|
size_t size;
|
|
@ -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
|
|
@ -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);
|
|
@ -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
|
25
src/main.c
25
src/main.c
|
@ -19,10 +19,7 @@
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
|
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
|
||||||
//=-------------------------------------------------------------------------=//
|
//=-------------------------------------------------------------------------=//
|
||||||
|
|
||||||
#include <pthread.h>
|
#include "../include/base.h"
|
||||||
#include <stdio.h>
|
|
||||||
#include <malloc.h>
|
|
||||||
#include "../include/types.h"
|
|
||||||
#include "../include/server.h"
|
#include "../include/server.h"
|
||||||
#include "../include/scheduler.h"
|
#include "../include/scheduler.h"
|
||||||
|
|
||||||
|
@ -38,7 +35,7 @@ int main(int argc, char **argv)
|
||||||
BoolArray_t *globalPreemptionSpace = NULL;
|
BoolArray_t *globalPreemptionSpace = NULL;
|
||||||
IntArray_t *globalDrawingSpace = NULL;
|
IntArray_t *globalDrawingSpace = NULL;
|
||||||
IntArray_t *arrowList = NULL;
|
IntArray_t *arrowList = NULL;
|
||||||
//IntArray_t *transitionTree = NULL;
|
IntArray_t *transitionsTree = NULL;
|
||||||
|
|
||||||
globalPreemptionSpace = (BoolArray_t*) malloc(sizeof(BoolArray_t));
|
globalPreemptionSpace = (BoolArray_t*) malloc(sizeof(BoolArray_t));
|
||||||
globalPreemptionSpace->space = (bool*) malloc(sizeof(bool)*SPACE_SIZE);
|
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->space = (int*) malloc(sizeof(int)*ARROW_NUMBER);
|
||||||
arrowList->size = ARROW_NUMBER;
|
arrowList->size = ARROW_NUMBER;
|
||||||
|
|
||||||
printf("globalPreemptionSpace: %p, size: %lu\n", globalPreemptionSpace, globalDrawingSpace->size);
|
printf("globalPreemptionSpace: %p, size: %lu\n", globalPreemptionSpace,
|
||||||
printf("globalDrawingSpace: %p, size: %lu\n", globalDrawingSpace, globalDrawingSpace->size);
|
globalDrawingSpace->size);
|
||||||
|
printf("globalDrawingSpace: %p, size: %lu\n", globalDrawingSpace,
|
||||||
|
globalDrawingSpace->size);
|
||||||
printf("arrowList: %p, size: %lu\n", arrowList, arrowList->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->space);
|
||||||
free(globalDrawingSpace);
|
free(globalDrawingSpace);
|
||||||
|
|
||||||
free(globalPreemptionSpace->space);
|
free(globalPreemptionSpace->space);
|
||||||
free(globalPreemptionSpace);
|
free(globalPreemptionSpace);
|
||||||
|
|
||||||
free(arrowList->space);
|
free(arrowList->space);
|
||||||
free(arrowList);
|
free(arrowList);
|
||||||
|
|
||||||
return 0;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,14 +19,33 @@
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
|
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
|
||||||
//=-------------------------------------------------------------------------=//
|
//=-------------------------------------------------------------------------=//
|
||||||
|
|
||||||
#include <pthread.h>
|
#include "../include/base.h"
|
||||||
#include <stdio.h>
|
|
||||||
#include <malloc.h>
|
|
||||||
#include "../include/types.h"
|
|
||||||
#include "../include/localthread.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)
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void *GreatScheduler(void *vargp)
|
||||||
|
{
|
||||||
|
sleep(1);
|
||||||
|
printf("Printing from thread \n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue