[commtech] Simplify if's in send()
Test sender_ptr against the end of the current buffer via channel->sender_ptr_end
This commit is contained in:
parent
a20c9a8a21
commit
7c4a484989
|
@ -15,64 +15,45 @@ struct channel
|
|||
{
|
||||
/* 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)));
|
||||
struct channel *mapping1; /* accesses to buf[0] and state */
|
||||
struct channel *mapping2; /* accesses to buf[1] */
|
||||
uintptr_t buf_mask;
|
||||
int unused[20] __attribute__ ((aligned (CACHE_LINE_SIZE)));
|
||||
volatile unsigned int state:1 __attribute__ ((aligned (CACHE_LINE_SIZE)));
|
||||
|
||||
/* 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;
|
||||
|
||||
void * volatile *sender_ptr __attribute__ ((aligned (CACHE_LINE_SIZE)));
|
||||
void * volatile *sender_ptr_end;
|
||||
void * volatile *receiver_ptr __attribute__ ((aligned (CACHE_LINE_SIZE)));
|
||||
};
|
||||
|
||||
#ifndef _BATCH_QUEUE_C_
|
||||
#ifndef PAGE_SIZE_HELPER
|
||||
#define PAGE_SIZE_HELPER 1
|
||||
uintptr_t _bq_page_mask;
|
||||
void *create_comm_channel_internal(void);
|
||||
static void *create_comm_channel_helper(void) __attribute__ ((unused));
|
||||
|
||||
static void *create_comm_channel_helper(void)
|
||||
{
|
||||
int ret;
|
||||
struct channel *channel;
|
||||
|
||||
ret = sysconf(_SC_PAGESIZE);
|
||||
if (ret == -1)
|
||||
return NULL;
|
||||
_bq_page_mask = ~(ret - 1);
|
||||
channel = create_comm_channel_internal();
|
||||
channel->buf_mask = sizeof channel->buf[0] - 1;
|
||||
return channel;
|
||||
}
|
||||
|
||||
#else
|
||||
extern unsigned int _bq_page_mask;
|
||||
#endif /* PAGE_SIZE_HELPER */
|
||||
|
||||
#define create_comm_channel() create_comm_channel_helper()
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
static inline void send(struct channel *channel, void **addr)
|
||||
{
|
||||
uintptr_t sender_ptr_high;
|
||||
|
||||
*channel->sender_ptr++ = addr;
|
||||
if (unlikely(!((uintptr_t) channel->sender_ptr & channel->buf_mask)))
|
||||
if (unlikely(channel->sender_ptr == channel->sender_ptr_end))
|
||||
{
|
||||
while (channel->state);
|
||||
channel->state = 1;
|
||||
sender_ptr_high =
|
||||
(uintptr_t) channel->sender_ptr & _bq_page_mask;
|
||||
if ((void *) sender_ptr_high == channel->mapping1)
|
||||
if (channel->sender_ptr_end == channel->buf_end1)
|
||||
{
|
||||
channel->sender_ptr = channel->mapping2->buf[1];
|
||||
channel->sender_ptr_end = channel->buf_end2;
|
||||
}
|
||||
else
|
||||
channel->sender_ptr = channel->mapping1->buf[0];
|
||||
{
|
||||
channel->sender_ptr = channel->buf[0];
|
||||
channel->sender_ptr_end = channel->buf_end1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif /* _BATCH_QUEUE_C_ */
|
||||
|
||||
#endif
|
||||
|
|
|
@ -23,7 +23,7 @@ static int nb_buf_entries;
|
|||
static unsigned int page_size;
|
||||
|
||||
|
||||
void *create_comm_channel_internal(void)
|
||||
void *create_comm_channel(void)
|
||||
{
|
||||
int ret, shm_fd;
|
||||
static int chan_idx = 0;
|
||||
|
@ -83,6 +83,12 @@ void *create_comm_channel_internal(void)
|
|||
channel1->sender_ptr = channel1->buf[0];
|
||||
channel1->receiver_ptr = channel1->buf[0];
|
||||
|
||||
channel1->buf_end1 = channel1->buf[0] +
|
||||
(sizeof channel1->buf[0] / sizeof channel1->buf[0][0]);
|
||||
channel1->buf_end2 = channel1->mapping2->buf[1] +
|
||||
(sizeof channel1->buf[1] / sizeof channel1->buf[1][0]);
|
||||
channel1->sender_ptr_end = channel1->buf_end1;
|
||||
|
||||
buf_mask = sizeof channel1->buf[0] - 1;
|
||||
nb_buf_entries = sizeof channel1->buf[0] / sizeof channel1->buf[0][0];
|
||||
close_file:
|
||||
|
|
Loading…
Reference in New Issue