2009-06-10 09:58:50 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
|
|
|
|
/* 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>
|
|
|
|
|
|
|
|
|
2009-06-17 18:15:16 +02:00
|
|
|
__thread struct comm_channel channel;
|
2009-06-10 09:58:50 +02:00
|
|
|
|
2009-06-24 22:25:28 +02:00
|
|
|
int init_thread_comm(struct thread_comm *comm)
|
2009-06-10 09:58:50 +02:00
|
|
|
{
|
2009-06-18 14:48:07 +02:00
|
|
|
comm->receiver_idx = 0;
|
|
|
|
comm->channel = &channel;
|
|
|
|
comm->channel->state = 0;
|
|
|
|
comm->channel->idx = 0;
|
2009-06-24 22:25:28 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int end_thread_comm(void)
|
|
|
|
{
|
|
|
|
return 0;
|
2009-06-10 09:58:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
char *dstr="buffer transition\n";
|
|
|
|
|
|
|
|
void _swap_buffer()
|
|
|
|
{
|
|
|
|
asm volatile(".globl swap_buffer\n\t"
|
|
|
|
"swap_buffer:\n\t"
|
|
|
|
|
|
|
|
"1:\n\t"
|
|
|
|
"testl $1, %%gs:channel@NTPOFF + 2 *" toString(BUF_SIZE) "\n\t"
|
|
|
|
"jnz 1b\n\t"
|
|
|
|
"movl $1, %%gs:channel@NTPOFF + 2 *" toString(BUF_SIZE) "\n\t"
|
|
|
|
"jmp *%%eax\n\t"
|
|
|
|
: : "m"(dstr));
|
|
|
|
}
|
|
|
|
|
2009-06-18 14:48:07 +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();
|
2009-06-10 09:58:50 +02:00
|
|
|
/* printf("Activate the consumer...\n"); */
|
2009-06-17 18:15:16 +02:00
|
|
|
while (cont)
|
2009-06-10 09:58:50 +02:00
|
|
|
{
|
2009-06-17 18:15:16 +02:00
|
|
|
int i;
|
2009-06-10 09:58:50 +02:00
|
|
|
|
2009-06-17 18:15:16 +02:00
|
|
|
for (i = 0; i < nb_prod; i++)
|
2009-06-10 09:58:50 +02:00
|
|
|
{
|
2009-06-17 18:15:16 +02:00
|
|
|
if(tcomms[i].channel->state)
|
2009-06-10 09:58:50 +02:00
|
|
|
{
|
2009-06-17 18:15:16 +02:00
|
|
|
int j, n;
|
2009-06-10 09:58:50 +02:00
|
|
|
/*
|
|
|
|
* 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)
|
|
|
|
*/
|
2009-06-17 18:15:16 +02:00
|
|
|
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++)
|
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].channel->buf[j]);
|
|
|
|
}
|
2009-06-17 18:15:16 +02:00
|
|
|
tcomms[i].channel->state = 0;
|
2009-06-10 09:58:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|