lsquic_alarmset.h revision 50aadb33
150aadb33SDmitri Tikhonov/* Copyright (c) 2017 LiteSpeed Technologies Inc.  See LICENSE. */
250aadb33SDmitri Tikhonov/*
350aadb33SDmitri Tikhonov * lsquic_alarmset.h -- A set of alarms
450aadb33SDmitri Tikhonov */
550aadb33SDmitri Tikhonov
650aadb33SDmitri Tikhonov#ifndef LSQUIC_ALARM_H
750aadb33SDmitri Tikhonov#define LSQUIC_ALARM_H 1
850aadb33SDmitri Tikhonov
950aadb33SDmitri Tikhonov#include "lsquic_int_types.h"
1050aadb33SDmitri Tikhonov
1150aadb33SDmitri Tikhonovtypedef void (*lsquic_alarm_cb_f)(void *cb_ctx,
1250aadb33SDmitri Tikhonov                                  lsquic_time_t expiry, lsquic_time_t now);
1350aadb33SDmitri Tikhonov
1450aadb33SDmitri Tikhonovtypedef struct lsquic_alarm {
1550aadb33SDmitri Tikhonov    lsquic_alarm_cb_f           callback;
1650aadb33SDmitri Tikhonov    void                       *cb_ctx;
1750aadb33SDmitri Tikhonov} lsquic_alarm_t;
1850aadb33SDmitri Tikhonov
1950aadb33SDmitri Tikhonov
2050aadb33SDmitri Tikhonovenum alarm_id {
2150aadb33SDmitri Tikhonov    AL_HANDSHAKE,
2250aadb33SDmitri Tikhonov    AL_RETX,
2350aadb33SDmitri Tikhonov    AL_ACK,
2450aadb33SDmitri Tikhonov    AL_PING,
2550aadb33SDmitri Tikhonov    AL_IDLE,
2650aadb33SDmitri Tikhonov    MAX_LSQUIC_ALARMS
2750aadb33SDmitri Tikhonov};
2850aadb33SDmitri Tikhonov
2950aadb33SDmitri Tikhonov
3050aadb33SDmitri Tikhonovenum alarm_id_bit {
3150aadb33SDmitri Tikhonov    ALBIT_HANDSHAKE = 1 << AL_HANDSHAKE,
3250aadb33SDmitri Tikhonov    ALBIT_RETX      = 1 << AL_RETX,
3350aadb33SDmitri Tikhonov    ALBIT_ACK       = 1 << AL_ACK,
3450aadb33SDmitri Tikhonov    ALBIT_PING      = 1 << AL_PING,
3550aadb33SDmitri Tikhonov    ALBIT_IDLE      = 1 << AL_IDLE,
3650aadb33SDmitri Tikhonov};
3750aadb33SDmitri Tikhonov
3850aadb33SDmitri Tikhonov
3950aadb33SDmitri Tikhonovtypedef struct lsquic_alarmset {
4050aadb33SDmitri Tikhonov    enum alarm_id_bit           as_armed_set;
4150aadb33SDmitri Tikhonov    lsquic_time_t               as_expiry[MAX_LSQUIC_ALARMS];
4250aadb33SDmitri Tikhonov    lsquic_cid_t                as_cid;    /* Used for logging */
4350aadb33SDmitri Tikhonov    struct lsquic_alarm         as_alarms[MAX_LSQUIC_ALARMS];
4450aadb33SDmitri Tikhonov} lsquic_alarmset_t;
4550aadb33SDmitri Tikhonov
4650aadb33SDmitri Tikhonov
4750aadb33SDmitri Tikhonovvoid
4850aadb33SDmitri Tikhonovlsquic_alarmset_init (lsquic_alarmset_t *, lsquic_cid_t);
4950aadb33SDmitri Tikhonov
5050aadb33SDmitri Tikhonovvoid
5150aadb33SDmitri Tikhonovlsquic_alarmset_init_alarm (lsquic_alarmset_t *, enum alarm_id,
5250aadb33SDmitri Tikhonov                            lsquic_alarm_cb_f, void *cb_ctx);
5350aadb33SDmitri Tikhonov
5450aadb33SDmitri Tikhonov#define lsquic_alarmset_set(alarmset, al_id, exp) do {                  \
5550aadb33SDmitri Tikhonov    (alarmset)->as_armed_set |= 1 << (al_id);                           \
5650aadb33SDmitri Tikhonov    (alarmset)->as_expiry[al_id] = exp;                                 \
5750aadb33SDmitri Tikhonov} while (0)
5850aadb33SDmitri Tikhonov
5950aadb33SDmitri Tikhonov#define lsquic_alarmset_unset(alarmset, al_id) do {                     \
6050aadb33SDmitri Tikhonov    (alarmset)->as_armed_set &= ~(1 << (al_id));                        \
6150aadb33SDmitri Tikhonov} while (0)
6250aadb33SDmitri Tikhonov
6350aadb33SDmitri Tikhonov#define lsquic_alarmset_is_set(alarmset, al_id) \
6450aadb33SDmitri Tikhonov                            ((alarmset)->as_armed_set & (1 << (al_id)))
6550aadb33SDmitri Tikhonov
6650aadb33SDmitri Tikhonov/* Timers "fire," alarms "ring." */
6750aadb33SDmitri Tikhonovvoid
6850aadb33SDmitri Tikhonovlsquic_alarmset_ring_expired (lsquic_alarmset_t *, lsquic_time_t now);
6950aadb33SDmitri Tikhonov
7050aadb33SDmitri Tikhonov#endif
71