63 lines
1.4 KiB
C
63 lines
1.4 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <pthread.h>
|
|
|
|
/* Non standard include */
|
|
#include <common_comm.h>
|
|
#include <specific_comm.h>
|
|
|
|
|
|
__thread struct comm_channel channel;
|
|
|
|
void init_thread_comm(void)
|
|
{
|
|
static int i = 0;
|
|
static pthread_mutex_t i_lock = PTHREAD_MUTEX_INITIALIZER;
|
|
int i_local;
|
|
|
|
pthread_mutex_lock(&i_lock);
|
|
i_local = i;
|
|
pthread_mutex_unlock(&i_lock);
|
|
tcomms[i].receiver_idx = 0;
|
|
tcomms[i].channel = &channel;
|
|
tcomms[i].channel->state = 0;
|
|
tcomms[i].channel->idx = 0;
|
|
pthread_mutex_lock(&i_lock);
|
|
i++;
|
|
pthread_mutex_unlock(&i_lock);
|
|
}
|
|
|
|
char *dstr="buffer transition\n";
|
|
|
|
void reception(void (*on_receive)(volatile void *))
|
|
{
|
|
/* printf("Activate the consumer...\n"); */
|
|
while (cont)
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; i < nb_prod; i++)
|
|
{
|
|
if(tcomms[i].channel->state)
|
|
{
|
|
int j, n;
|
|
/*
|
|
* cur->receiver_idx point to the last cache
|
|
* line we have read. We go to the next cache
|
|
* line "+ (CACHE_LINE_SIZE >> 2)" (because
|
|
* the line is full of integer (2^2 octets)
|
|
* and then if we are after the second cache
|
|
* line we correct the pointer to point to
|
|
* the first one (this is done by the modulo)
|
|
*/
|
|
j = tcomms[i].receiver_idx;
|
|
n = tcomms[i].receiver_idx + (BUF_SIZE / sizeof(void *));
|
|
tcomms[i].receiver_idx = n % ((2 * BUF_SIZE) / sizeof(void *));
|
|
for(; j<n; j++)
|
|
on_receive(tcomms[i].channel->buf[j]);
|
|
tcomms[i].channel->state = 0;
|
|
}
|
|
}
|
|
}
|
|
}
|