2009-06-18 14:48:07 +02:00
|
|
|
#ifndef _SPECIFIC_COMM_H_
|
|
|
|
#define _SPECIFIC_COMM_H_ 1
|
2009-06-11 23:42:15 +02:00
|
|
|
|
|
|
|
/* Non standard include */
|
2009-06-18 14:48:07 +02:00
|
|
|
#include <commtech.h>
|
2009-06-11 23:42:15 +02:00
|
|
|
|
|
|
|
#define SHARED_SPACE_SIZE (2 * BUF_SIZE)
|
2009-06-16 12:58:30 +02:00
|
|
|
#define SHARED_SPACE_VOIDPTR (SHARED_SPACE_SIZE / sizeof(void *))
|
2009-06-11 23:42:15 +02:00
|
|
|
|
2010-09-22 18:15:57 +02:00
|
|
|
struct comm
|
2009-06-11 23:42:15 +02:00
|
|
|
{
|
2010-09-22 18:15:57 +02:00
|
|
|
void * volatile *shared_space;
|
|
|
|
volatile int cons_idx __attribute__ ((aligned (CACHE_LINE_SIZE)));
|
|
|
|
volatile int prod_idx __attribute__ ((aligned (CACHE_LINE_SIZE)));
|
2009-06-11 23:42:15 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
__BEGIN_DECLS
|
|
|
|
|
2010-09-22 18:15:57 +02:00
|
|
|
extern __thread struct comm *comm;
|
2009-06-11 23:42:15 +02:00
|
|
|
|
2010-09-22 18:15:57 +02:00
|
|
|
static inline void send(void **addr)
|
|
|
|
{
|
2009-06-11 23:42:15 +02:00
|
|
|
static __thread int local_cons_idx = 0;
|
2010-09-22 18:15:57 +02:00
|
|
|
int local_prod, next_prod;
|
2009-06-11 23:42:15 +02:00
|
|
|
|
2010-09-22 18:15:57 +02:00
|
|
|
local_prod = comm->prod_idx;
|
|
|
|
next_prod = (local_prod + 1) % SHARED_SPACE_VOIDPTR;
|
|
|
|
if (next_prod == local_cons_idx)
|
2009-06-11 23:42:15 +02:00
|
|
|
{
|
2010-09-22 18:15:57 +02:00
|
|
|
while (next_prod == comm->cons_idx);
|
|
|
|
local_cons_idx = comm->cons_idx;
|
2009-06-11 23:42:15 +02:00
|
|
|
}
|
2010-09-22 18:15:57 +02:00
|
|
|
comm->shared_space[local_prod] = addr;
|
|
|
|
comm->prod_idx = next_prod;
|
2009-06-11 23:42:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
__END_DECLS
|
|
|
|
|
|
|
|
#endif
|