2011-04-11 15:34:49 +02:00
|
|
|
#ifndef _BATCH_QUEUE_COMMON_COMM_H_
|
|
|
|
#define _BATCH_QUEUE_COMMON_COMM_H_ 1
|
2009-06-17 19:18:38 +02:00
|
|
|
|
2011-05-30 16:23:43 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2009-06-17 19:18:38 +02:00
|
|
|
/* Non standard include */
|
2009-06-18 14:48:07 +02:00
|
|
|
#include <commtech.h>
|
2009-06-17 19:18:38 +02:00
|
|
|
|
2011-03-02 12:20:47 +01:00
|
|
|
#ifndef BUF_SIZE
|
|
|
|
#define BUF_SIZE (32 * CACHE_LINE_SIZE)
|
|
|
|
#endif
|
|
|
|
|
2010-09-22 18:15:57 +02:00
|
|
|
struct channel
|
2009-06-17 19:18:38 +02:00
|
|
|
{
|
2011-05-30 16:23:43 +02:00
|
|
|
/* buf must be the first field to allow the buf_mask test */
|
|
|
|
void * volatile buf[2][BUF_SIZE / sizeof(void *)] __attribute__ ((aligned (CACHE_LINE_SIZE)));
|
2011-03-02 12:49:09 +01:00
|
|
|
int unused[20] __attribute__ ((aligned (CACHE_LINE_SIZE)));
|
2011-05-10 13:43:55 +02:00
|
|
|
volatile unsigned int state:1 __attribute__ ((aligned (CACHE_LINE_SIZE)));
|
2011-06-06 13:34:01 +02:00
|
|
|
|
|
|
|
/* accesses to buf[0] and state */
|
|
|
|
struct channel *mapping1 __attribute__ ((aligned (CACHE_LINE_SIZE)));
|
|
|
|
/* accesses to buf[1] */
|
|
|
|
struct channel *mapping2;
|
|
|
|
void * volatile *buf_end1;
|
|
|
|
void * volatile *buf_end2;
|
|
|
|
|
2011-05-30 16:23:43 +02:00
|
|
|
void * volatile *sender_ptr __attribute__ ((aligned (CACHE_LINE_SIZE)));
|
2011-06-06 13:34:01 +02:00
|
|
|
void * volatile *sender_ptr_end;
|
2011-05-30 16:23:43 +02:00
|
|
|
void * volatile *receiver_ptr __attribute__ ((aligned (CACHE_LINE_SIZE)));
|
2010-09-22 18:15:57 +02:00
|
|
|
};
|
|
|
|
|
2009-06-17 19:18:38 +02:00
|
|
|
|
|
|
|
__BEGIN_DECLS
|
|
|
|
|
2011-04-11 16:18:49 +02:00
|
|
|
static inline void send(struct channel *channel, void **addr)
|
2009-06-17 19:18:38 +02:00
|
|
|
{
|
2011-05-30 16:23:43 +02:00
|
|
|
|
|
|
|
*channel->sender_ptr++ = addr;
|
2011-06-06 13:34:01 +02:00
|
|
|
if (unlikely(channel->sender_ptr == channel->sender_ptr_end))
|
2009-06-17 19:18:38 +02:00
|
|
|
{
|
2011-04-11 16:18:49 +02:00
|
|
|
while (channel->state);
|
|
|
|
channel->state = 1;
|
2011-06-06 13:34:01 +02:00
|
|
|
if (channel->sender_ptr_end == channel->buf_end1)
|
|
|
|
{
|
2011-05-30 16:23:43 +02:00
|
|
|
channel->sender_ptr = channel->mapping2->buf[1];
|
2011-06-06 13:34:01 +02:00
|
|
|
channel->sender_ptr_end = channel->buf_end2;
|
|
|
|
}
|
2011-05-30 16:23:43 +02:00
|
|
|
else
|
2011-06-06 13:34:01 +02:00
|
|
|
{
|
|
|
|
channel->sender_ptr = channel->buf[0];
|
|
|
|
channel->sender_ptr_end = channel->buf_end1;
|
|
|
|
}
|
2009-06-17 19:18:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
__END_DECLS
|
|
|
|
|
|
|
|
#endif
|