rt_benchs/communication_techniques/include/shared_mem_opt_comm.h

42 lines
923 B
C

#ifndef _SPECIFIC_COMM_H_
#define _SPECIFIC_COMM_H_ 1
/* Non standard include */
#include <commtech.h>
#define SHARED_SPACE_SIZE (2 * BUF_SIZE)
#define SHARED_SPACE_VOIDPTR (SHARED_SPACE_SIZE / sizeof(void *))
struct thread_comm
{
volatile void **shared_space;
volatile int *cons_idx;
volatile int *prod_idx;
};
extern struct thread_comm *tcomms;
__BEGIN_DECLS
extern __thread volatile void **shared_space;
extern __thread volatile int prod_idx;
extern __thread volatile int cons_idx;
int init_thread_comm(struct thread_comm *);
int end_thread_comm(void);
static inline void send(void **addr) {
static __thread int local_cons_idx = 0;
if (likely(((prod_idx + 1) % SHARED_SPACE_VOIDPTR) == local_cons_idx))
{
while (((prod_idx + 1) % SHARED_SPACE_VOIDPTR) == cons_idx);
local_cons_idx = cons_idx;
}
shared_space[prod_idx] = addr;
prod_idx = (prod_idx + 1) % SHARED_SPACE_VOIDPTR;
}
__END_DECLS
#endif