Line data Source code
1 : #ifndef HEADER_fd_src_tango_quic_fd_quic_stream_pool_h 2 : #define HEADER_fd_src_tango_quic_fd_quic_stream_pool_h 3 : 4 : #include "fd_quic_stream.h" 5 : 6 : /* stream pool alignment */ 7 14238 : #define FD_QUIC_STREAM_POOL_ALIGN 128ul 8 : 9 : struct fd_quic_stream_pool { 10 : ulong cap; /* the capacity of the pool */ 11 : ulong cur_cnt; /* the current number of streams in the pool */ 12 : fd_quic_stream_t head[1]; /* the head of the linked list of free streams, or NULL if none */ 13 : }; 14 : 15 : typedef struct fd_quic_stream_pool fd_quic_stream_pool_t; 16 : 17 : FD_PROTOTYPES_BEGIN 18 : 19 : /* returns the alignment of the fd_quic_stream_pool_t */ 20 : FD_FN_CONST static inline 21 : ulong 22 0 : fd_quic_stream_pool_align( void ) { 23 0 : return FD_QUIC_STREAM_POOL_ALIGN; 24 0 : } 25 : 26 : /* returns the required footprint of fd_quic_stream_pool_t 27 : 28 : args 29 : count the number of streams the pool will manage */ 30 : FD_FN_CONST 31 : ulong 32 : fd_quic_stream_pool_footprint( ulong count, ulong tx_buf_sz ); 33 : 34 : /* returns a newly initialized stream pool 35 : 36 : args 37 : mem the memory aligned to fd_quic_stream_pool_align, and at least fd_quic_stream_pool_footprint 38 : bytes 39 : count the number of streams the pool will manage 40 : type the stream type used for the streams managed by this pool */ 41 : fd_quic_stream_pool_t * 42 : fd_quic_stream_pool_new( void * mem, ulong count, ulong tx_buf_sz ); 43 : 44 : /* delete a stream pool 45 : 46 : this will also delete all the associated streams 47 : 48 : All streams should be freed back to the pool before this function is called 49 : 50 : args 51 : stream_pool the stream pool to free */ 52 : void 53 : fd_quic_stream_pool_delete( fd_quic_stream_pool_t * stream_pool ); 54 : 55 : /* allocates a stream from the pool 56 : 57 : args 58 : stream_pool the pool from which to obtain the stream 59 : 60 : returns 61 : the newly allocated stream, or NULL if no streams are available */ 62 : fd_quic_stream_t * 63 : fd_quic_stream_pool_alloc( fd_quic_stream_pool_t * pool ); 64 : 65 : /* free a stream to the specified pool 66 : 67 : args 68 : stream_pool the pool to return the stream to 69 : stream the stream to return */ 70 : void 71 : fd_quic_stream_pool_free( fd_quic_stream_pool_t * pool, fd_quic_stream_t * stream ); 72 : 73 : /* returns the number of streams available in the pool */ 74 : static inline 75 : ulong 76 0 : fd_quic_stream_pool_avail( fd_quic_stream_pool_t * pool ) { 77 0 : return pool->cur_cnt; 78 0 : } 79 : 80 : FD_PROTOTYPES_END 81 : 82 : #endif