#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