39 lines
900 B
C
39 lines
900 B
C
#ifndef _SPECIFIC_COMM_H_
|
|
#define _SPECIFIC_COMM_H_ 1
|
|
|
|
/* Non standard include */
|
|
#include <commtech.h>
|
|
|
|
#define SHARED_SPACE_SIZE (2 * CACHE_LINE_SIZE)
|
|
#define SHARED_SPACE_VOIDPTR (SHARED_SPACE_SIZE / sizeof(void *))
|
|
|
|
struct channel
|
|
{
|
|
void * volatile *shared_space;
|
|
volatile unsigned int cons_idx __attribute__ ((aligned (CACHE_LINE_SIZE)));
|
|
volatile unsigned int prod_idx __attribute__ ((aligned (CACHE_LINE_SIZE)));
|
|
};
|
|
|
|
|
|
__BEGIN_DECLS
|
|
|
|
static inline void send(struct channel *channel, void **addr)
|
|
{
|
|
static __thread unsigned int local_cons_idx = 0;
|
|
unsigned int local_prod, next_prod;
|
|
|
|
local_prod = channel->prod_idx;
|
|
next_prod = (local_prod + 1) % SHARED_SPACE_VOIDPTR;
|
|
if (next_prod == local_cons_idx)
|
|
{
|
|
while (next_prod == channel->cons_idx);
|
|
local_cons_idx = channel->cons_idx;
|
|
}
|
|
channel->shared_space[local_prod] = addr;
|
|
channel->prod_idx = next_prod;
|
|
}
|
|
|
|
__END_DECLS
|
|
|
|
#endif
|