59 lines
1.1 KiB
C
59 lines
1.1 KiB
C
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <semaphore.h>
|
||
|
#include <unistd.h>
|
||
|
#include <pthread.h>
|
||
|
#include "messageAdder.h"
|
||
|
#include "msg.h"
|
||
|
#include "iMessageAdder.h"
|
||
|
#include "mySoftware.h"
|
||
|
#include "iAcquisitionManager.h"
|
||
|
#include "debug.h"
|
||
|
|
||
|
//consumer thread
|
||
|
pthread_t consumer;
|
||
|
//Message computed
|
||
|
volatile MSG_BLOCK out;
|
||
|
//Consumer count storage
|
||
|
volatile unsigned int consumeCount = 0;
|
||
|
|
||
|
/**
|
||
|
* Increments the consume count.
|
||
|
*/
|
||
|
static void incrementConsumeCount(void);
|
||
|
|
||
|
/**
|
||
|
* Consumer entry point.
|
||
|
*/
|
||
|
static void *sum( void *parameters );
|
||
|
|
||
|
//TODO create accessors to limit semaphore and mutex usage outside of this C module.
|
||
|
|
||
|
void messageAdderInit(void){
|
||
|
out.checksum = 0;
|
||
|
for (size_t i = 0; i < DATA_SIZE; i++)
|
||
|
{
|
||
|
out.mData[i] = 0;
|
||
|
pthread_create(&consumer, NULL, sum, NULL);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void messageAdderJoin(void){
|
||
|
pthread_join(consumer, NULL);
|
||
|
}
|
||
|
|
||
|
static void *sum( void *parameters )
|
||
|
{
|
||
|
D(printf("[messageAdder] Thread created for sum with id %ld\n", gettid()));
|
||
|
unsigned int i = 0;
|
||
|
while(i<ADDER_LOOP_LIMIT){
|
||
|
i++;
|
||
|
sleep(ADDER_SLEEP_TIME);
|
||
|
//TODO
|
||
|
}
|
||
|
printf("[messageAdder] %ld termination\n", gettid());
|
||
|
pthread_exit(NULL);
|
||
|
}
|
||
|
|
||
|
|