53 lines
1.1 KiB
C
53 lines
1.1 KiB
C
#ifndef _SPECIFIC_COMM_H_
|
|
#define _SPECIFIC_COMM_H_ 1
|
|
|
|
/* Non standard include */
|
|
#include <commtech.h>
|
|
#include <assert.h>
|
|
|
|
#define SHARED_SPACE_SIZE (16 * BUF_SIZE)
|
|
#define SHARED_SPACE_VOIDPTR (SHARED_SPACE_SIZE / sizeof(void *))
|
|
|
|
#ifndef BUF_SIZE
|
|
#define BUF_SIZE CACHE_LINE_SIZE
|
|
#endif
|
|
|
|
#define DANGER (2 * BUF_SIZE / sizeof(void *))
|
|
#define GOOD (6 * BUF_SIZE / sizeof(void *))
|
|
#define ADJUST_FREQ 64
|
|
|
|
struct channel
|
|
{
|
|
void * volatile *shared_space;
|
|
unsigned int head __attribute__ ((aligned (CACHE_LINE_SIZE)));
|
|
unsigned int tail __attribute__ ((aligned (CACHE_LINE_SIZE)));
|
|
};
|
|
|
|
__BEGIN_DECLS
|
|
|
|
extern int adjust_slip(struct channel *channel);
|
|
|
|
static inline void send(struct channel *channel, void **addr)
|
|
{
|
|
static __thread unsigned int nb_iter = 0;
|
|
|
|
assert(addr != NULL);
|
|
if (nb_iter == ADJUST_FREQ)
|
|
{
|
|
adjust_slip(channel);
|
|
nb_iter = 0;
|
|
}
|
|
while (1)
|
|
{
|
|
if (channel->shared_space[channel->head] != NULL)
|
|
continue;
|
|
channel->shared_space[channel->head] = addr;
|
|
channel->head = (channel->head + 1) % SHARED_SPACE_VOIDPTR;
|
|
break;
|
|
}
|
|
}
|
|
|
|
__END_DECLS
|
|
|
|
#endif
|