rt_benchs/communication_techniques/include/commtech.h

99 lines
3.0 KiB
C

/*
* Copyright (C) 2009-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 _COMMTECH_H_
#define _COMMTECH_H_ 1
#define CACHE_LINE_SIZE 64
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect((x), 0)
__BEGIN_DECLS
struct channel;
/*
* @return a pointer on the channel if success, NULL else
*
* Create a communication channel. The return value is the address of
* the channel that has to be passed to init_producer_thread and
* init_consumer_thread respectively by the producer and consumer thread
* which want to communicate.
*/
void *create_comm_channel(void);
/*
* @param channel The channel to destroy
* @return 0 if success, -1 else
*
* Destroy a communication channel.
*
* @comment Must be called after producer and consumer stopped to
* communicate.
*/
int destroy_comm_channel(void *);
/*
* @param channel The production channel
* @return 0 if success, -1 else
*
* Notify the communication algorithm that the producer has finished producing
*
* @comment Must be called by the producer when it has finished producing
*/
int end_producer(void *);
/*
* @param channel Channel from which to receive data
* @return a data sent by the matching producer
*
* Wait until a data sent by the matching producer is available
*
* @comment recv_one_data should not be used in conjonction of
* recv_some_data
*/
void *recv_one_data(struct channel *);
/*
* @param channel Channel from which to receive data
* @param buf The buffer to write received data into
* @param count The maximum number of data to copy into buf
* @return Number of data copied into buf
*
* Wait until some data sent by the matching producer is available and
* copy as much data as possible into buf, with a maximum of count.
*
* @commentrecv_some_data should not be used in conjonction of recv_one_data
* @comment count must be a multiple of BUF_SIZE / sizeof(void *) which is
* equal to SUB_SLOTS
*/
ssize_t recv_some_data(struct channel *, void **, size_t);
__END_DECLS
#endif