rt_benchs/communication_techniques/include/mcringbuffer_comm.h

71 lines
1.5 KiB
C
Raw Normal View History

2010-09-22 18:15:57 +02:00
#ifndef _SPECIFIC_COMM_H_
#define _SPECIFIC_COMM_H_ 1
/* Non standard include */
#include <commtech.h>
#define SHARED_SPACE_SIZE (250 * CACHE_LINE_SIZE) // Check with batchSize
2010-09-22 18:15:57 +02:00
#define SHARED_SPACE_VOIDPTR (SHARED_SPACE_SIZE / sizeof(void *))
struct control
{
2011-05-10 13:43:55 +02:00
volatile unsigned int read;
volatile unsigned int write;
2010-09-22 18:15:57 +02:00
};
struct cons
{
2011-05-10 13:43:55 +02:00
unsigned int localWrite;
unsigned int nextRead;
unsigned int rBatch;
2010-09-22 18:15:57 +02:00
};
struct prod
{
2011-05-10 13:43:55 +02:00
unsigned int localRead;
unsigned int nextWrite;
unsigned int wBatch;
2010-09-22 18:15:57 +02:00
};
struct channel
2010-09-22 18:15:57 +02:00
{
struct control ctrl __attribute__ ((aligned (CACHE_LINE_SIZE)));
struct prod prod __attribute__ ((aligned (CACHE_LINE_SIZE)));
struct cons cons __attribute__ ((aligned (CACHE_LINE_SIZE)));
void * volatile *shared_space __attribute__ ((aligned (CACHE_LINE_SIZE))); // Align only to isolate cons on its cache line
};
__BEGIN_DECLS
2011-05-10 13:43:55 +02:00
extern const unsigned int batchSize;
2010-09-22 18:15:57 +02:00
static inline void send(struct channel *channel, void **addr)
2010-09-22 18:15:57 +02:00
{
while (1)
{
2011-05-10 13:43:55 +02:00
unsigned int afterNextWrite;
afterNextWrite = (channel->prod.nextWrite + 1) % SHARED_SPACE_VOIDPTR;
if (afterNextWrite == channel->prod.localRead)
2010-09-22 18:15:57 +02:00
{
if (afterNextWrite == channel->ctrl.read)
2010-09-22 18:15:57 +02:00
continue;
channel->prod.localRead = channel->ctrl.read;
2010-09-22 18:15:57 +02:00
}
channel->shared_space[channel->prod.nextWrite] = addr;
channel->prod.nextWrite = afterNextWrite;
channel->prod.wBatch++;
if (channel->prod.wBatch >= batchSize)
2010-09-22 18:15:57 +02:00
{
channel->ctrl.write = channel->prod.nextWrite;
channel->prod.wBatch = 0;
2010-09-22 18:15:57 +02:00
}
break;
}
}
__END_DECLS
#endif