#ifndef _CSQ_COMMON_COMM_H_ #define _CSQ_COMMON_COMM_H_ 1 /* Non standard include */ #include #ifndef BUF_SIZE #define BUF_SIZE CACHE_LINE_SIZE #endif #ifndef SLOTS #define SLOTS 64 /* Value used in the article, section V.A */ #endif #define SUB_SLOTS (BUF_SIZE / sizeof(void *)) struct lvl_2 { void * volatile chunk[SUB_SLOTS]; volatile unsigned int flag : 1; } __attribute__ ((aligned (CACHE_LINE_SIZE))); struct channel { struct lvl_2 queue[SLOTS] __attribute__ ((aligned (CACHE_LINE_SIZE))); unsigned int head __attribute__ ((aligned(CACHE_LINE_SIZE))); unsigned int tail __attribute__ ((aligned(CACHE_LINE_SIZE))); }; __BEGIN_DECLS // TODO: Make it send only one data static inline void send(struct channel *channel, void **addr) { static __thread unsigned int chkidx = 0; // If all slots are full, spin if (!chkidx) while (channel->queue[channel->tail].flag); // Enqueue a data item channel->queue[channel->tail].chunk[chkidx++] = addr; if (!(chkidx % SUB_SLOTS)) { chkidx = 0; channel->queue[channel->tail].flag = 1; channel->tail = (channel->tail + 1) % SLOTS; } } __END_DECLS #endif