M2_SETI/T2/tp/exercice-1/displayManager.c
2022-11-19 16:11:18 +01:00

47 lines
1 KiB
C
Executable file

#include <unistd.h>
#include <stdio.h>
#include <pthread.h>
#include "displayManager.h"
#include "iDisplay.h"
#include "iAcquisitionManager.h"
#include "iMessageAdder.h"
#include "msg.h"
#include "multitaskingAccumulator.h"
#include "debug.h"
// DisplayManager thread.
pthread_t displayThread;
/**
* Display manager entry point.
* */
static void *display( void *parameters );
void displayManagerInit(void){
// TODO DONE
pthread_create(&displayThread, NULL, display, NULL);
}
void displayManagerJoin(void){
//TODO DONE
pthread_join(displayThread, NULL);
}
static void *display( void *parameters )
{
D(printf("[displayManager]Thread created for display with id %d\n", getpid()));
unsigned int diffCount = 0;
MSG_BLOCK mBlock;
while(diffCount < DISPLAY_LOOP_LIMIT){
sleep(DISPLAY_SLEEP_TIME);
//TODO
diffCount++;
mBlock = getCurrentSum();
messageDisplay(&mBlock);
print(getProducedCount(),getConsumedCount());
}
printf("[displayManager] %d termination\n", getpid());
//TODO DONE
pthread_exit(NULL);
}