46 lines
999 B
C
46 lines
999 B
C
#ifndef __COMM_H_
|
|
#define __COMM_H_ 1
|
|
|
|
#include <stdint.h>
|
|
|
|
/* Non standard include */
|
|
#include <common_comm.h>
|
|
|
|
#define SHARED_SPACE_SIZE (2 * BUF_SIZE)
|
|
#define SHARED_SPACE_VOIDPTR (SHARED_SPACE_SIZE / sizeof(void *))
|
|
|
|
struct communication_assoc
|
|
{
|
|
struct communication_assoc *next;
|
|
struct communication_assoc *prev;
|
|
pthread_t tid;
|
|
void **shared_space;
|
|
volatile int *cons_idx;
|
|
volatile int *prod_idx;
|
|
};
|
|
|
|
extern struct communication_assoc assoc_root;
|
|
|
|
__BEGIN_DECLS
|
|
|
|
extern __thread void **shared_space;
|
|
extern __thread volatile int prod_idx;
|
|
extern __thread volatile int cons_idx;
|
|
|
|
struct communication_assoc *create_comm_assoc(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
|