#include #include #include /* Non standard include */ #include #include #include __thread struct comm_channel channel; void init_thread_comm(struct thread_comm *comm) { comm->receiver_idx = 0; comm->channel = &channel; comm->channel->state = 0; comm->channel->idx = 0; } 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)); } void reception(void (*on_receive)(void *)) { wait_initialization(); /* 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(; jbuf[j]); } tcomms[i].channel->state = 0; } } } }