lsquic_alarmset.h revision 10c492f0
1/* Copyright (c) 2017 - 2018 LiteSpeed Technologies Inc. See LICENSE. */ 2/* 3 * lsquic_alarmset.h -- A set of alarms 4 */ 5 6#ifndef LSQUIC_ALARM_H 7#define LSQUIC_ALARM_H 1 8 9#include "lsquic_int_types.h" 10 11typedef void (*lsquic_alarm_cb_f)(void *cb_ctx, 12 lsquic_time_t expiry, lsquic_time_t now); 13 14typedef struct lsquic_alarm { 15 lsquic_alarm_cb_f callback; 16 void *cb_ctx; 17} lsquic_alarm_t; 18 19 20enum alarm_id { 21 AL_HANDSHAKE, 22 AL_RETX, 23 AL_ACK, 24 AL_PING, 25 AL_IDLE, 26 MAX_LSQUIC_ALARMS 27}; 28 29 30enum alarm_id_bit { 31 ALBIT_HANDSHAKE = 1 << AL_HANDSHAKE, 32 ALBIT_RETX = 1 << AL_RETX, 33 ALBIT_ACK = 1 << AL_ACK, 34 ALBIT_PING = 1 << AL_PING, 35 ALBIT_IDLE = 1 << AL_IDLE, 36}; 37 38 39typedef struct lsquic_alarmset { 40 enum alarm_id_bit as_armed_set; 41 lsquic_time_t as_expiry[MAX_LSQUIC_ALARMS]; 42 lsquic_cid_t as_cid; /* Used for logging */ 43 struct lsquic_alarm as_alarms[MAX_LSQUIC_ALARMS]; 44} lsquic_alarmset_t; 45 46 47void 48lsquic_alarmset_init (lsquic_alarmset_t *, lsquic_cid_t); 49 50void 51lsquic_alarmset_init_alarm (lsquic_alarmset_t *, enum alarm_id, 52 lsquic_alarm_cb_f, void *cb_ctx); 53 54#define lsquic_alarmset_set(alarmset, al_id, exp) do { \ 55 (alarmset)->as_armed_set |= 1 << (al_id); \ 56 (alarmset)->as_expiry[al_id] = exp; \ 57} while (0) 58 59#define lsquic_alarmset_unset(alarmset, al_id) do { \ 60 (alarmset)->as_armed_set &= ~(1 << (al_id)); \ 61} while (0) 62 63#define lsquic_alarmset_is_set(alarmset, al_id) \ 64 ((alarmset)->as_armed_set & (1 << (al_id))) 65 66/* Timers "fire," alarms "ring." */ 67void 68lsquic_alarmset_ring_expired (lsquic_alarmset_t *, lsquic_time_t now); 69 70#endif 71