ids don't need to be allocated dynamically
This commit is contained in:
parent
3b26597bd6
commit
48ca39577a
|
@ -85,7 +85,7 @@ struct {
|
||||||
int nMaxThread;
|
int nMaxThread;
|
||||||
int nMaxCycles;
|
int nMaxCycles;
|
||||||
int ruleRadius;
|
int ruleRadius;
|
||||||
pthread_t *id;
|
pthread_t id;
|
||||||
bool pleaseStop;
|
bool pleaseStop;
|
||||||
} typedef Scheduler_t;
|
} typedef Scheduler_t;
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ struct Center_t {
|
||||||
} typedef Center_t;
|
} typedef Center_t;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
pthread_t *id;
|
pthread_t id;
|
||||||
Center_t *localWorkAreaCenter;
|
Center_t *localWorkAreaCenter;
|
||||||
Space_t *globalDrawingSpace;
|
Space_t *globalDrawingSpace;
|
||||||
IntArray_t *conditionTree;
|
IntArray_t *conditionTree;
|
||||||
|
@ -120,7 +120,7 @@ struct {
|
||||||
// Server
|
// Server
|
||||||
//
|
//
|
||||||
struct {
|
struct {
|
||||||
pthread_t *id;
|
pthread_t id;
|
||||||
bool pleaseStop;
|
bool pleaseStop;
|
||||||
} typedef Server_t;
|
} typedef Server_t;
|
||||||
|
|
||||||
|
@ -136,7 +136,7 @@ struct {
|
||||||
// Supervisor
|
// Supervisor
|
||||||
//
|
//
|
||||||
struct {
|
struct {
|
||||||
pthread_t *id;
|
pthread_t id;
|
||||||
bool pleaseStop;
|
bool pleaseStop;
|
||||||
int *workerCreationOccurency;
|
int *workerCreationOccurency;
|
||||||
} typedef Supervisor_t;
|
} typedef Supervisor_t;
|
||||||
|
|
|
@ -37,8 +37,7 @@ static inline void WorkerDestroy(Worker_t *worker)
|
||||||
worker->terminated = false;
|
worker->terminated = false;
|
||||||
worker->returnValue = false;
|
worker->returnValue = false;
|
||||||
|
|
||||||
free(worker->id);
|
worker->id = 0;
|
||||||
worker->id = NULL;
|
|
||||||
free(worker->localWorkAreaCenter);
|
free(worker->localWorkAreaCenter);
|
||||||
worker->localWorkAreaCenter = NULL;
|
worker->localWorkAreaCenter = NULL;
|
||||||
}
|
}
|
||||||
|
@ -48,5 +47,5 @@ static inline void WorkerDestroy(Worker_t *worker)
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
static inline void WorkerWait(Worker_t *worker)
|
static inline void WorkerWait(Worker_t *worker)
|
||||||
{
|
{
|
||||||
pthread_join(*worker->id, NULL);
|
pthread_join(worker->id, NULL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,6 @@ void SchedInit(Scheduler_t *scheduler);
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
static inline void SchedDestroy(Scheduler_t *scheduler)
|
static inline void SchedDestroy(Scheduler_t *scheduler)
|
||||||
{
|
{
|
||||||
free(scheduler->id);
|
|
||||||
free(scheduler->globalDrawingSpace->space);
|
free(scheduler->globalDrawingSpace->space);
|
||||||
free(scheduler->globalDrawingSpace);
|
free(scheduler->globalDrawingSpace);
|
||||||
|
|
||||||
|
@ -46,5 +45,5 @@ static inline void SchedDestroy(Scheduler_t *scheduler)
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
static inline void SchedWait(Scheduler_t *scheduler)
|
static inline void SchedWait(Scheduler_t *scheduler)
|
||||||
{
|
{
|
||||||
pthread_join(*scheduler->id, NULL);
|
pthread_join(scheduler->id, NULL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,6 @@ void ServerInit(Server_t *server);
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
static inline void ServerDestroy(Server_t *server)
|
static inline void ServerDestroy(Server_t *server)
|
||||||
{
|
{
|
||||||
free(server->id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
|
@ -41,5 +40,5 @@ static inline void ServerDestroy(Server_t *server)
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
static inline void ServerWait(Server_t *server)
|
static inline void ServerWait(Server_t *server)
|
||||||
{
|
{
|
||||||
pthread_join(*server->id, NULL);
|
pthread_join(server->id, NULL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,6 @@ void SupervisorInit(Supervisor_t *supervisor);
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
static inline void SupervisorDestroy(Supervisor_t *supervisor)
|
static inline void SupervisorDestroy(Supervisor_t *supervisor)
|
||||||
{
|
{
|
||||||
free(supervisor->id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
|
@ -41,5 +40,5 @@ static inline void SupervisorDestroy(Supervisor_t *supervisor)
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
static inline void SupervisorWait(Supervisor_t *supervisor)
|
static inline void SupervisorWait(Supervisor_t *supervisor)
|
||||||
{
|
{
|
||||||
pthread_join(*supervisor->id, NULL);
|
pthread_join(supervisor->id, NULL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,9 +30,8 @@ static void *workerMain(void *worker);
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
void WorkerInit(Worker_t *worker)
|
void WorkerInit(Worker_t *worker)
|
||||||
{
|
{
|
||||||
worker->id = (pthread_t*) calloc(1, sizeof(pthread_t));
|
if (pthread_create(&worker->id, NULL, workerMain, worker)) {
|
||||||
if (pthread_create(worker->id, NULL, workerMain, worker)) {
|
printLog("Worker #%lu can't be initialized!\n", worker->id);
|
||||||
printLog("Worker #%lu can't be initialized!\n", *(worker->id));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,7 +45,7 @@ static void *workerMain(void *worker)
|
||||||
int a = rand()%__INT_MAX__;
|
int a = rand()%__INT_MAX__;
|
||||||
|
|
||||||
args = (Worker_t*) worker;
|
args = (Worker_t*) worker;
|
||||||
printLog("Worker #%lu online\n", *args->id);
|
printLog("Worker #%lu online\n", args->id);
|
||||||
|
|
||||||
int size = args->globalDrawingSpace->size;
|
int size = args->globalDrawingSpace->size;
|
||||||
/* In each cell: the West (left) site is 0, the East (right) site is 1 */
|
/* In each cell: the West (left) site is 0, the East (right) site is 1 */
|
||||||
|
@ -85,7 +84,7 @@ static void *workerMain(void *worker)
|
||||||
args->returnValue = a;
|
args->returnValue = a;
|
||||||
args->terminated = true;
|
args->terminated = true;
|
||||||
|
|
||||||
printLog("Worker #%lu offline\n", *args->id);
|
printLog("Worker #%lu offline\n", args->id);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,8 +35,7 @@ static void *schedulerMain(void *scheduler);
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
void SchedInit(Scheduler_t *scheduler)
|
void SchedInit(Scheduler_t *scheduler)
|
||||||
{
|
{
|
||||||
scheduler->id = (pthread_t*) calloc(1, sizeof(pthread_t));
|
pthread_create(&scheduler->id, NULL, schedulerMain, scheduler);
|
||||||
pthread_create(scheduler->id, NULL, schedulerMain, scheduler);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
@ -88,7 +87,7 @@ static void *schedulerMain(void *scheduler)
|
||||||
|
|
||||||
// Getting scheduler argument structure
|
// Getting scheduler argument structure
|
||||||
args = (Scheduler_t*) scheduler;
|
args = (Scheduler_t*) scheduler;
|
||||||
printLog("Scheduler #%lu online\n", *args->id);
|
printLog("Scheduler #%lu online\n", args->id);
|
||||||
|
|
||||||
if (!args->nMaxThread) { // nmaxthread = 0 => no minimum
|
if (!args->nMaxThread) { // nmaxthread = 0 => no minimum
|
||||||
ncpu = get_nprocs(); // allocating all the cpus available
|
ncpu = get_nprocs(); // allocating all the cpus available
|
||||||
|
@ -181,7 +180,7 @@ static void *schedulerMain(void *scheduler)
|
||||||
// Remove preemption on space
|
// Remove preemption on space
|
||||||
CenterRemove(workerArray[i].localWorkAreaCenter);
|
CenterRemove(workerArray[i].localWorkAreaCenter);
|
||||||
printLog("Worker #%lu terminated with return %d. Cleaning...\n",
|
printLog("Worker #%lu terminated with return %d. Cleaning...\n",
|
||||||
*workerArray[i].id,
|
workerArray[i].id,
|
||||||
workerArray[i].returnValue
|
workerArray[i].returnValue
|
||||||
);
|
);
|
||||||
// Remove Worker
|
// Remove Worker
|
||||||
|
@ -197,13 +196,13 @@ static void *schedulerMain(void *scheduler)
|
||||||
// Waiting for remaining workers
|
// Waiting for remaining workers
|
||||||
for (int i = 0; i < ncpu; i++) {
|
for (int i = 0; i < ncpu; i++) {
|
||||||
if (workerArray[i].id) {
|
if (workerArray[i].id) {
|
||||||
printLog("Waiting for termination of worker #%lu\n", *workerArray[i].id);
|
printLog("Waiting for termination of worker #%lu\n", workerArray[i].id);
|
||||||
// Join the thread to wait for his termination
|
// Join the thread to wait for his termination
|
||||||
WorkerWait(&workerArray[i]);
|
WorkerWait(&workerArray[i]);
|
||||||
// Remove preemption on space
|
// Remove preemption on space
|
||||||
CenterRemove(workerArray[i].localWorkAreaCenter);
|
CenterRemove(workerArray[i].localWorkAreaCenter);
|
||||||
printLog("Worker #%lu terminated with return %d. Cleaning...\n",
|
printLog("Worker #%lu terminated with return %d. Cleaning...\n",
|
||||||
*workerArray[i].id,
|
workerArray[i].id,
|
||||||
workerArray[i].returnValue
|
workerArray[i].returnValue
|
||||||
);
|
);
|
||||||
// Remove Worker
|
// Remove Worker
|
||||||
|
@ -211,7 +210,7 @@ static void *schedulerMain(void *scheduler)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printLog("Scheduler #%lu offline\n", *args->id);
|
printLog("Scheduler #%lu offline\n", args->id);
|
||||||
|
|
||||||
free(workerArray);
|
free(workerArray);
|
||||||
free(centersList);
|
free(centersList);
|
||||||
|
|
|
@ -35,8 +35,7 @@ static void *serverMain(void *server);
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
void ServerInit(Server_t *server)
|
void ServerInit(Server_t *server)
|
||||||
{
|
{
|
||||||
server->id = (pthread_t*) calloc(1, sizeof(pthread_t));
|
pthread_create(&server->id, NULL, serverMain, server);
|
||||||
pthread_create(server->id, NULL, serverMain, server);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define SEND_BUFFER_SIZE 80 * 24
|
#define SEND_BUFFER_SIZE 80 * 24
|
||||||
|
@ -107,7 +106,7 @@ static void *serverMain(void *server)
|
||||||
|
|
||||||
// Get args
|
// Get args
|
||||||
args = (Server_t*) server;
|
args = (Server_t*) server;
|
||||||
printLog("Server #%lu online\n", *args->id);
|
printLog("Server #%lu online\n", args->id);
|
||||||
|
|
||||||
// Create socket
|
// Create socket
|
||||||
sockfd = socket(AF_INET, SOCK_STREAM, 0);
|
sockfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
|
@ -157,6 +156,6 @@ serverExiting:
|
||||||
close(sockfd);
|
close(sockfd);
|
||||||
|
|
||||||
serverEarlyExiting:
|
serverEarlyExiting:
|
||||||
printLog("Server #%lu offline\n", *args->id);
|
printLog("Server #%lu offline\n", args->id);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,8 +30,7 @@ static void *supervisorMain(void *supervisor);
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
void SupervisorInit(Supervisor_t *supervisor)
|
void SupervisorInit(Supervisor_t *supervisor)
|
||||||
{
|
{
|
||||||
supervisor->id = (pthread_t*) calloc(1, sizeof(pthread_t));
|
pthread_create(&supervisor->id, NULL, supervisorMain, supervisor);
|
||||||
pthread_create(supervisor->id, NULL, supervisorMain, supervisor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
|
|
Loading…
Reference in New Issue