lsquic_pacer.h revision 6aba801d
1/* Copyright (c) 2017 - 2019 LiteSpeed Technologies Inc.  See LICENSE. */
2#ifndef LSQUIC_PACER_H
3#define LSQUIC_PACER_H 1
4
5struct pacer
6{
7    lsquic_cid_t    pa_cid;             /* Used for logging */
8    lsquic_time_t   pa_next_sched;
9    lsquic_time_t   pa_last_delayed;
10    lsquic_time_t   pa_now;
11
12    /* All tick times are in microseconds */
13
14    unsigned        pa_clock_granularity;
15
16    unsigned        pa_burst_tokens;
17    enum {
18        PA_LAST_SCHED_DELAYED   = (1 << 0),
19    }               pa_flags;
20#ifndef NDEBUG
21    struct {
22        unsigned        n_scheduled;
23    }               pa_stats;
24#endif
25};
26
27
28typedef lsquic_time_t (*tx_time_f)(void *ctx);
29
30void
31pacer_init (struct pacer *, lsquic_cid_t, unsigned clock_granularity);
32
33void
34pacer_cleanup (struct pacer *);
35
36void
37pacer_tick (struct pacer *, lsquic_time_t);
38
39int
40pacer_can_schedule (struct pacer *, unsigned n_in_flight);
41
42void
43pacer_packet_scheduled (struct pacer *pacer, unsigned n_in_flight,
44                        int in_recovery, tx_time_f tx_time, void *tx_ctx);
45
46void
47pacer_loss_event (struct pacer *);
48
49#define pacer_delayed(pacer) ((pacer)->pa_flags & PA_LAST_SCHED_DELAYED)
50
51#define pacer_next_sched(pacer) (+(pacer)->pa_next_sched)
52
53#endif
54