48 lines
892 B
C
48 lines
892 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <pthread.h>
|
|
#include <unistd.h>
|
|
|
|
/* Non standard include */
|
|
#include <common_comm.h>
|
|
#include <specific_comm.h>
|
|
|
|
|
|
__thread int pipefd[2];
|
|
|
|
struct communication_assoc *create_comm_assoc(void)
|
|
{
|
|
struct communication_assoc *assoc;
|
|
|
|
pipe(pipefd);
|
|
assoc = (struct communication_assoc *) malloc(sizeof(struct communication_assoc));
|
|
assoc->tid = pthread_self();
|
|
assoc->pipefd = pipefd;
|
|
return assoc;
|
|
}
|
|
|
|
void reception(void (*on_receive)(void *))
|
|
{
|
|
wait_initialization();
|
|
/* printf("Activate the consumer...\n"); */
|
|
while(cont)
|
|
{
|
|
struct communication_assoc *cur;
|
|
|
|
discover_new_producers();
|
|
cur = assoc_root.next;
|
|
while(cur != &assoc_root)
|
|
{
|
|
int i;
|
|
|
|
for(i = 0; i < BUF_SIZE / sizeof(void *); i++)
|
|
{
|
|
void *tmp;
|
|
read(cur->pipefd[READ_IDX], &tmp, sizeof(void *));
|
|
on_receive(tmp);
|
|
}
|
|
cur = cur->next;
|
|
}
|
|
}
|
|
}
|