82 lines
2.6 KiB
C
82 lines
2.6 KiB
C
/*
|
|
* Copyright (C) 2012 Thomas Preud'homme <thomas.preud-homme@lip6.fr>
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
* in the Software without restriction, including without limitation the rights
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
* furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in
|
|
* all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
* SOFTWARE.
|
|
*/
|
|
|
|
#ifndef _BATCH_QUEUE_COMMON_COMM_H_
|
|
#define _BATCH_QUEUE_COMMON_COMM_H_ 1
|
|
|
|
#include <stdint.h>
|
|
#include <unistd.h>
|
|
|
|
/* Non standard include */
|
|
#include <commtech.h>
|
|
|
|
#ifndef BUF_SIZE
|
|
#define BUF_SIZE (32 * CACHE_LINE_SIZE)
|
|
#endif
|
|
|
|
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)));
|
|
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)));
|
|
};
|
|
|
|
|
|
__BEGIN_DECLS
|
|
|
|
static inline void send(struct channel *channel, void **addr)
|
|
{
|
|
|
|
*channel->sender_ptr++ = addr;
|
|
if (unlikely(channel->sender_ptr == channel->sender_ptr_end))
|
|
{
|
|
while (channel->state);
|
|
channel->state = 1;
|
|
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->buf[0];
|
|
channel->sender_ptr_end = channel->buf_end1;
|
|
}
|
|
}
|
|
}
|
|
|
|
__END_DECLS
|
|
|
|
#endif
|