rt_benchs/communication_techniques/include/commtech.h

129 lines
3.0 KiB
C

#ifndef _COMMTECH_H_
#define _COMMTECH_H_ 1
#define CACHE_LINE_SIZE 128
#define BUF_SIZE CACHE_LINE_SIZE
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
__BEGIN_DECLS
/*
* @return 0 if success, -1 else
*
* Initialize communication library.
* @comment Must be run before any other function of this library
*/
int init_library(void);
/*
* @return 0 if success, -1 else
*
* Finalize communication library.
* @comment Must be run after any other function of this library
*/
int finalize_library(void);
/*
* @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 chan Address of the communication channel to attach to
* the producer calling this function.
* @return 0 on success, -1 else
*
* Initialize the producer and attach the given communication channel to
* it.
*/
int init_producer_thread(void *);
/*
* @param channel Address of the communication channel to detach from
* the producer calling this function
* @return 0 on success, -1 else
*
* Finalize the producer.
* @comment Must be run by the producer after it stopped to communicate
* with the consumer.
*/
int finalize_producer_thread(void *);
/*
* @param channel Address of the communication channel to attach to
* the consumer calling this function.
* @return 0 on success, -1 else
*
* Initialize the consumer and attach the given communication channel to
* it.
*/
int init_consumer_thread(void *);
/*
* @param channel Address of the communication channel to detach from
* the consumer calling this function
* @return 0 on success, -1 else
*
* Finalize the consumer.
*
* @comment Must be run by the consumer after it stopped to communicate
* with the consumer.
*/
int finalize_consumer_thread(void *);
/*
* @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(void);
/*
* @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(void **, size_t);
__END_DECLS
#endif