2009-06-11 23:42:15 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
/* Non standard include */
|
2009-06-18 14:48:07 +02:00
|
|
|
#include <commtech.h>
|
|
|
|
#include <private_common.h>
|
2009-06-11 23:42:15 +02:00
|
|
|
#include <specific_comm.h>
|
|
|
|
|
|
|
|
|
2009-06-18 14:48:07 +02:00
|
|
|
__thread volatile void **shared_space;
|
2009-06-12 00:36:31 +02:00
|
|
|
__thread volatile int cons_idx = 0;
|
|
|
|
__thread volatile int prod_idx = 0;
|
2009-06-11 23:42:15 +02:00
|
|
|
|
2009-06-18 14:48:07 +02:00
|
|
|
void init_thread_comm(struct thread_comm *comm)
|
2009-06-11 23:42:15 +02:00
|
|
|
{
|
2009-06-18 14:48:07 +02:00
|
|
|
shared_space = (volatile void **) malloc(SHARED_SPACE_SIZE);
|
|
|
|
comm->shared_space = shared_space;
|
|
|
|
comm->cons_idx = &cons_idx;
|
|
|
|
comm->prod_idx = &prod_idx;
|
2009-06-11 23:42:15 +02:00
|
|
|
}
|
|
|
|
|
2009-06-16 12:58:30 +02:00
|
|
|
void reception(void (*on_receive)(void *))
|
2009-06-11 23:42:15 +02:00
|
|
|
{
|
|
|
|
wait_initialization();
|
|
|
|
/* printf("Activate the consumer...\n"); */
|
|
|
|
while(cont)
|
|
|
|
{
|
2009-06-18 14:48:07 +02:00
|
|
|
int i;
|
2009-06-11 23:42:15 +02:00
|
|
|
|
2009-06-18 14:48:07 +02:00
|
|
|
for( i = 0; i < nb_prod; i++)
|
2009-06-11 23:42:15 +02:00
|
|
|
{
|
|
|
|
int cons_idx, prod_idx;
|
|
|
|
|
2009-06-18 14:48:07 +02:00
|
|
|
cons_idx = *tcomms[i].cons_idx;
|
2009-06-11 23:42:15 +02:00
|
|
|
do
|
|
|
|
{
|
2009-06-18 14:48:07 +02:00
|
|
|
prod_idx = *tcomms[i].prod_idx;
|
2009-06-16 12:58:30 +02:00
|
|
|
for(; cons_idx != prod_idx; cons_idx = (cons_idx + 1) % SHARED_SPACE_VOIDPTR)
|
2009-06-11 23:42:15 +02:00
|
|
|
{
|
2009-06-18 14:48:07 +02:00
|
|
|
/*
|
|
|
|
* The behaviour of this is not documented but we know
|
|
|
|
* the values inside buf won't change during this affectation
|
|
|
|
*/
|
|
|
|
on_receive((void *) tcomms[i].shared_space[cons_idx]);
|
2009-06-11 23:42:15 +02:00
|
|
|
}
|
2009-06-18 14:48:07 +02:00
|
|
|
} while (prod_idx != *tcomms[i].prod_idx);
|
|
|
|
*tcomms[i].cons_idx = cons_idx;
|
2009-06-11 23:42:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|