1 #ifndef BUFFERS_H_ /* so that this file is not included twice */ 2 #define BUFFERS_H_ 3 4 /** buffer size --- adjust to be a multiplicity of the 5 striping factor in a parallel filesystem */ 6 #define DBL_BUF_SIZE 131072 7 8 #define BUF_SIZE (DBL_BUF_SIZE*sizeof(double)) 9 #define INT_BUF_SIZE (BUF_SIZE/sizeof(int)) 10 11 /* alignment factor for the internal buffer */ 12 #define ALIGN 16 13 14 #define MAXBUF 16 /* max # of buffers that can be used */ 15 #define DEFBUF 4 /* default # of buffers */ 16 17 /** internal buffer structure */ 18 typedef struct { 19 char *buffer; 20 int align_off; /**< caching alignment offset */ 21 int buf_hdl; /**< buffer handle; index of the buffer in the ctxt */ 22 int group_id; /**< identify callback function to use to release buffer */ 23 int call_id; /**< id to be used to complete an entire call */ 24 int active; /**< if the buffer active or not */ 25 } _buffer_t; 26 27 /** structure to create application context */ 28 typedef struct { 29 int ctxt_id; 30 _buffer_t *buf; /**< will be allocated nbuf buffers*/ 31 int nbuf; 32 int size; /**< in bytes */ 33 void (*fptr)(char*); /**< array of pointers to functions provided 34 by the application */ 35 int last_buf; /* utility variable; 36 contains the last buf assigned in this ctxt */ 37 } buf_context_t; 38 39 void buffer_init(buf_context_t *ctxt, int nbuf, int buf_size, void (*fptr)(char*)); 40 char *get_buf(buf_context_t *ctxt, int call_id); 41 void buf_terminate(buf_context_t *ctxt); 42 void buf_complete_call(buf_context_t *ctxt, int call_id); 43 int buf_get_call_id(buf_context_t *ctxt, char *buf); 44 int get_bufs_of_call_id(buf_context_t *ctxt, int call_id, int *n_buf, char *bufs[]); 45 void free_buf(buf_context_t *ctxt, char *buf); 46 47 #endif /* BUFFERS_H_ */ 48