2009-06-10 09:58:50 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <unistd.h>
|
2009-06-18 14:48:07 +02:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdint.h>
|
2009-06-10 09:58:50 +02:00
|
|
|
|
|
|
|
/* Non standard include */
|
2009-06-18 14:48:07 +02:00
|
|
|
#include <commtech.h>
|
|
|
|
#include <private_common.h>
|
2009-06-10 09:58:50 +02:00
|
|
|
#include <specific_comm.h>
|
|
|
|
|
|
|
|
|
|
|
|
__thread int pipefd[2];
|
|
|
|
|
2009-06-18 14:48:07 +02:00
|
|
|
void init_thread_comm(struct thread_comm *comm)
|
2009-06-10 09:58:50 +02:00
|
|
|
{
|
2009-06-18 14:48:07 +02:00
|
|
|
int flags;
|
2009-06-10 09:58:50 +02:00
|
|
|
|
|
|
|
pipe(pipefd);
|
2009-06-18 14:48:07 +02:00
|
|
|
flags = fcntl(pipefd[READ_IDX], F_GETFL);
|
|
|
|
fcntl(pipefd[READ_IDX], F_SETFL, flags | O_NONBLOCK);
|
|
|
|
comm->pipefd = pipefd;
|
2009-06-10 09:58:50 +02:00
|
|
|
}
|
|
|
|
|
2009-06-16 12:58:30 +02:00
|
|
|
void reception(void (*on_receive)(void *))
|
2009-06-10 09:58:50 +02:00
|
|
|
{
|
2009-06-18 14:48:07 +02:00
|
|
|
wait_initialization(); /* Not needed but here for equity with others techniques */
|
2009-06-10 09:58:50 +02:00
|
|
|
/* printf("Activate the consumer...\n"); */
|
|
|
|
while(cont)
|
|
|
|
{
|
2009-06-18 14:48:07 +02:00
|
|
|
int i;
|
2009-06-10 09:58:50 +02:00
|
|
|
|
2009-06-18 14:48:07 +02:00
|
|
|
for (i = 0; i < nb_prod; i++)
|
2009-06-10 09:58:50 +02:00
|
|
|
{
|
2009-06-18 14:48:07 +02:00
|
|
|
int nb_read;
|
2009-06-10 09:58:50 +02:00
|
|
|
|
2009-06-18 14:48:07 +02:00
|
|
|
for(nb_read = 0; nb_read < BUF_SIZE / sizeof(void *); nb_read++)
|
2009-06-10 09:58:50 +02:00
|
|
|
{
|
2009-06-18 14:48:07 +02:00
|
|
|
int j, n;
|
|
|
|
void *tmp_buf[BUF_SIZE / sizeof(void *)];
|
|
|
|
|
|
|
|
j = nb_read / sizeof(void *);
|
|
|
|
n = read(tcomms[i].pipefd[READ_IDX], (void *) ((uintptr_t) tmp_buf + nb_read), BUF_SIZE - nb_read);
|
|
|
|
if (n > 0)
|
|
|
|
{
|
|
|
|
nb_read += n;
|
|
|
|
for (; j + sizeof(void *) <= nb_read / sizeof(void *); j += sizeof(void *))
|
|
|
|
on_receive(tmp_buf[j]);
|
|
|
|
}
|
2009-06-10 09:58:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|