#ifndef _BATCH_QUEUE_COMMON_COMM_H_ #define _BATCH_QUEUE_COMMON_COMM_H_ 1 /* Non standard include */ #include #ifndef BUF_SIZE #define BUF_SIZE (32 * CACHE_LINE_SIZE) #endif /* This is not an error, we need this two-macro system */ #define toString(x) doStringification(x) #define doStringification(x) #x struct channel { void * volatile buf[2 * BUF_SIZE / sizeof(void *)] __attribute__ ((aligned (CACHE_LINE_SIZE))); int unused[20] __attribute__ ((aligned (CACHE_LINE_SIZE))); volatile int state __attribute__ ((aligned (CACHE_LINE_SIZE))); int idx __attribute__ ((aligned (CACHE_LINE_SIZE))); }; struct cons { struct channel *channel; int receiver_idx; }; union comm { struct channel *channel; struct cons *cons; }; extern __thread union comm comm; __BEGIN_DECLS static inline void send(void **addr) { comm.channel->buf[comm.channel->idx++] = addr; comm.channel->idx %= 2 * (BUF_SIZE / sizeof(void *)); if (!(comm.channel->idx % (BUF_SIZE / sizeof(void *)))) { while (comm.channel->state); comm.channel->state = 1; } } __END_DECLS #endif