#ifndef _SPECIFIC_COMM_H_ #define _SPECIFIC_COMM_H_ 1 #include /* Non standard include */ #include /* This is not an error, we need this two-macro system */ #define toString(x) doStringification(x) #define doStringification(x) #x struct communication_channel { uintptr_t buf[2 * BUF_SIZE / sizeof(uintptr_t)] __attribute__ ((aligned (CACHE_LINE_SIZE))); int state __attribute__ ((aligned (CACHE_LINE_SIZE))); int idx __attribute__ ((aligned (CACHE_LINE_SIZE))); }; struct communication_assoc { struct communication_assoc *next; struct communication_assoc *prev; pthread_t tid; struct communication_channel *channel; int receiver_idx; }; extern struct communication_assoc assoc_root; __BEGIN_DECLS struct communication_assoc *create_comm_assoc(void); static inline void send(uintptr_t value) { asm volatile("mov %%gs:channel@NTPOFF + 2 *" toString(BUF_SIZE) " + " toString(CACHE_LINE_SIZE) ", %%eax\n\t" "mov %0, %%gs:channel@NTPOFF(%%eax)\n\t" "addl $4, %%eax\n\t" "andl $(2*" toString(BUF_SIZE) "-1), %%eax\n\t" "mov %%eax, %%gs:channel@NTPOFF + 2 * " toString(BUF_SIZE)" + " toString(CACHE_LINE_SIZE) "\n\t" "test $(" toString(BUF_SIZE) " - 1), %%eax\n\t" "mov $2f, %%eax\n\t" "jz swap_buffer\n\t" "2:" : : "r"(value) : "%eax"); } __END_DECLS #endif