45 lines
970 B
C
45 lines
970 B
C
#ifndef _SPECIFIC_COMM_H_
|
|
#define _SPECIFIC_COMM_H_ 1
|
|
|
|
/* Non standard include */
|
|
#include <commtech.h>
|
|
|
|
/* This is not an error, we need this two-macro system */
|
|
#define toString(x) doStringification(x)
|
|
#define doStringification(x) #x
|
|
|
|
struct comm_channel
|
|
{
|
|
volatile void *buf[2 * BUF_SIZE / sizeof(void *)] __attribute__ ((aligned (CACHE_LINE_SIZE)));
|
|
volatile int state __attribute__ ((aligned (CACHE_LINE_SIZE)));
|
|
int idx __attribute__ ((aligned (CACHE_LINE_SIZE)));
|
|
};
|
|
|
|
struct thread_comm
|
|
{
|
|
struct comm_channel *channel;
|
|
int receiver_idx;
|
|
};
|
|
|
|
extern struct thread_comm *tcomms;
|
|
extern __thread struct comm_channel channel;
|
|
|
|
__BEGIN_DECLS
|
|
|
|
int init_thread_comm(struct thread_comm *);
|
|
int end_thread_comm(void);
|
|
static inline void send(void **addr)
|
|
{
|
|
channel.buf[channel.idx++] = addr;
|
|
channel.idx %= 2 * BUF_SIZE / sizeof(void *);
|
|
if (!(channel.idx % (BUF_SIZE / sizeof(void *))))
|
|
{
|
|
while (channel.state);
|
|
channel.state = 1;
|
|
}
|
|
}
|
|
|
|
__END_DECLS
|
|
|
|
#endif
|