rt_benchs/communication_techniques/include/c_cache_comm.h

46 lines
952 B
C

#ifndef _SPECIFIC_COMM_H_
#define _SPECIFIC_COMM_H_ 1
#include <stdint.h>
/* Non standard include */
#include <common_comm.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
void init_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