lsquic_mm.h revision 50aadb33
150aadb33SDmitri Tikhonov/* Copyright (c) 2017 LiteSpeed Technologies Inc.  See LICENSE. */
250aadb33SDmitri Tikhonov/*
350aadb33SDmitri Tikhonov * lsquic_mm.h -- Memory manager.
450aadb33SDmitri Tikhonov *
550aadb33SDmitri Tikhonov * Allocators and in this class are meant to be used for the lifetime of
650aadb33SDmitri Tikhonov * QUIC engine.
750aadb33SDmitri Tikhonov */
850aadb33SDmitri Tikhonov
950aadb33SDmitri Tikhonov#ifndef LSQUIC_MM_H
1050aadb33SDmitri Tikhonov#define LSQUIC_MM_H 1
1150aadb33SDmitri Tikhonov
1250aadb33SDmitri Tikhonovstruct lsquic_engine_public;
1350aadb33SDmitri Tikhonovstruct lsquic_packet_in;
1450aadb33SDmitri Tikhonovstruct lsquic_packet_out;
1550aadb33SDmitri Tikhonovstruct ack_info;
1650aadb33SDmitri Tikhonovstruct malo;
1750aadb33SDmitri Tikhonov
1850aadb33SDmitri Tikhonov#define MM_N_OUT_BUCKETS 3
1950aadb33SDmitri Tikhonov
2050aadb33SDmitri Tikhonovstruct lsquic_mm {
2150aadb33SDmitri Tikhonov    struct ack_info     *acki;
2250aadb33SDmitri Tikhonov    struct {
2350aadb33SDmitri Tikhonov        struct malo     *stream_frame;  /* For struct stream_frame */
2450aadb33SDmitri Tikhonov        struct malo     *stream_rec_arr;/* For struct stream_rec_arr */
2550aadb33SDmitri Tikhonov        struct malo     *packet_in;     /* For struct lsquic_packet_in */
2650aadb33SDmitri Tikhonov        struct malo     *packet_out;    /* For struct lsquic_packet_out */
2750aadb33SDmitri Tikhonov    }                    malo;
2850aadb33SDmitri Tikhonov    TAILQ_HEAD(, lsquic_packet_in)  free_packets_in;
2950aadb33SDmitri Tikhonov    SLIST_HEAD(, packet_out_buf)    packet_out_bufs[MM_N_OUT_BUCKETS];
3050aadb33SDmitri Tikhonov    SLIST_HEAD(, payload_buf)       payload_bufs;
3150aadb33SDmitri Tikhonov    SLIST_HEAD(, four_k_page)       four_k_pages;
3250aadb33SDmitri Tikhonov    SLIST_HEAD(, sixteen_k_page)    sixteen_k_pages;
3350aadb33SDmitri Tikhonov};
3450aadb33SDmitri Tikhonov
3550aadb33SDmitri Tikhonovint
3650aadb33SDmitri Tikhonovlsquic_mm_init (struct lsquic_mm *);
3750aadb33SDmitri Tikhonov
3850aadb33SDmitri Tikhonovvoid
3950aadb33SDmitri Tikhonovlsquic_mm_cleanup (struct lsquic_mm *);
4050aadb33SDmitri Tikhonov
4150aadb33SDmitri Tikhonovstruct lsquic_packet_in *
4250aadb33SDmitri Tikhonovlsquic_mm_get_packet_in (struct lsquic_mm *);
4350aadb33SDmitri Tikhonov
4450aadb33SDmitri Tikhonovvoid
4550aadb33SDmitri Tikhonovlsquic_mm_put_packet_in (struct lsquic_mm *, struct lsquic_packet_in *);
4650aadb33SDmitri Tikhonov
4750aadb33SDmitri Tikhonov#define lsquic_packet_in_put(mm, p) do {                                \
4850aadb33SDmitri Tikhonov    assert((p)->pi_refcnt != 0);                                        \
4950aadb33SDmitri Tikhonov    if (--(p)->pi_refcnt == 0)                                          \
5050aadb33SDmitri Tikhonov        lsquic_mm_put_packet_in(mm, p);                                 \
5150aadb33SDmitri Tikhonov} while (0)
5250aadb33SDmitri Tikhonov
5350aadb33SDmitri Tikhonovstruct lsquic_packet_out *
5450aadb33SDmitri Tikhonovlsquic_mm_get_packet_out (struct lsquic_mm *, struct malo *,
5550aadb33SDmitri Tikhonov                          unsigned short size);
5650aadb33SDmitri Tikhonov
5750aadb33SDmitri Tikhonovvoid
5850aadb33SDmitri Tikhonovlsquic_mm_put_packet_out (struct lsquic_mm *, struct lsquic_packet_out *);
5950aadb33SDmitri Tikhonov
6050aadb33SDmitri Tikhonovvoid *
6150aadb33SDmitri Tikhonovlsquic_mm_get_1370 (struct lsquic_mm *);
6250aadb33SDmitri Tikhonov
6350aadb33SDmitri Tikhonovvoid
6450aadb33SDmitri Tikhonovlsquic_mm_put_1370 (struct lsquic_mm *, void *);
6550aadb33SDmitri Tikhonov
6650aadb33SDmitri Tikhonovvoid *
6750aadb33SDmitri Tikhonovlsquic_mm_get_4k (struct lsquic_mm *);
6850aadb33SDmitri Tikhonov
6950aadb33SDmitri Tikhonovvoid
7050aadb33SDmitri Tikhonovlsquic_mm_put_4k (struct lsquic_mm *, void *);
7150aadb33SDmitri Tikhonov
7250aadb33SDmitri Tikhonovvoid *
7350aadb33SDmitri Tikhonovlsquic_mm_get_16k (struct lsquic_mm *);
7450aadb33SDmitri Tikhonov
7550aadb33SDmitri Tikhonovvoid
7650aadb33SDmitri Tikhonovlsquic_mm_put_16k (struct lsquic_mm *, void *);
7750aadb33SDmitri Tikhonov
7850aadb33SDmitri Tikhonov#endif
79