lsquic_mm.h revision 10c492f0
1/* Copyright (c) 2017 - 2018 LiteSpeed Technologies Inc. See LICENSE. */ 2/* 3 * lsquic_mm.h -- Memory manager. 4 * 5 * Allocators and in this class are meant to be used for the lifetime of 6 * QUIC engine. 7 */ 8 9#ifndef LSQUIC_MM_H 10#define LSQUIC_MM_H 1 11 12struct lsquic_engine_public; 13struct lsquic_packet_in; 14struct lsquic_packet_out; 15struct ack_info; 16struct malo; 17 18#define MM_N_OUT_BUCKETS 3 19 20struct lsquic_mm { 21 struct ack_info *acki; 22 struct { 23 struct malo *stream_frame; /* For struct stream_frame */ 24 struct malo *stream_rec_arr;/* For struct stream_rec_arr */ 25 struct malo *packet_in; /* For struct lsquic_packet_in */ 26 struct malo *packet_out; /* For struct lsquic_packet_out */ 27 } malo; 28 TAILQ_HEAD(, lsquic_packet_in) free_packets_in; 29 SLIST_HEAD(, packet_out_buf) packet_out_bufs[MM_N_OUT_BUCKETS]; 30 SLIST_HEAD(, payload_buf) payload_bufs; 31 SLIST_HEAD(, four_k_page) four_k_pages; 32 SLIST_HEAD(, sixteen_k_page) sixteen_k_pages; 33}; 34 35int 36lsquic_mm_init (struct lsquic_mm *); 37 38void 39lsquic_mm_cleanup (struct lsquic_mm *); 40 41struct lsquic_packet_in * 42lsquic_mm_get_packet_in (struct lsquic_mm *); 43 44void 45lsquic_mm_put_packet_in (struct lsquic_mm *, struct lsquic_packet_in *); 46 47#define lsquic_packet_in_put(mm, p) do { \ 48 assert((p)->pi_refcnt != 0); \ 49 if (--(p)->pi_refcnt == 0) \ 50 lsquic_mm_put_packet_in(mm, p); \ 51} while (0) 52 53struct lsquic_packet_out * 54lsquic_mm_get_packet_out (struct lsquic_mm *, struct malo *, 55 unsigned short size); 56 57void 58lsquic_mm_put_packet_out (struct lsquic_mm *, struct lsquic_packet_out *); 59 60void * 61lsquic_mm_get_1370 (struct lsquic_mm *); 62 63void 64lsquic_mm_put_1370 (struct lsquic_mm *, void *); 65 66void * 67lsquic_mm_get_4k (struct lsquic_mm *); 68 69void 70lsquic_mm_put_4k (struct lsquic_mm *, void *); 71 72void * 73lsquic_mm_get_16k (struct lsquic_mm *); 74 75void 76lsquic_mm_put_16k (struct lsquic_mm *, void *); 77 78size_t 79lsquic_mm_mem_used (const struct lsquic_mm *mm); 80 81#endif 82