rt_benchs/communication_techniques/include/lamport_comm.h

55 lines
1.9 KiB
C
Raw Normal View History

2013-04-22 18:30:08 +02:00
/*
* Copyright (C) 2010 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.
*/
2010-09-22 18:15:57 +02:00
#ifndef _SPECIFIC_COMM_H_
#define _SPECIFIC_COMM_H_ 1
/* Non standard include */
#include <commtech.h>
#ifndef BUF_SIZE
#define BUF_SIZE CACHE_LINE_SIZE
#endif
2010-09-22 18:15:57 +02:00
#define SHARED_SPACE_SIZE (2 * BUF_SIZE)
#define SHARED_SPACE_VOIDPTR (SHARED_SPACE_SIZE / sizeof(void *))
struct channel
2010-09-22 18:15:57 +02:00
{
void * volatile *shared_space;
2011-05-10 13:43:55 +02:00
volatile unsigned int cons_idx __attribute__ ((aligned (CACHE_LINE_SIZE)));
volatile unsigned int prod_idx __attribute__ ((aligned (CACHE_LINE_SIZE)));
2010-09-22 18:15:57 +02:00
};
__BEGIN_DECLS
static inline void send(struct channel *channel, void **addr)
2010-09-22 18:15:57 +02:00
{
while ((channel->prod_idx + 1) % SHARED_SPACE_VOIDPTR == channel->cons_idx);
channel->shared_space[channel->prod_idx] = addr;
channel->prod_idx = (channel->prod_idx + 1) % SHARED_SPACE_VOIDPTR;
2010-09-22 18:15:57 +02:00
}
__END_DECLS
#endif