]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: Add function for TX packets reference counting
authorFrédéric Lécaille <flecaille@haproxy.com>
Fri, 16 Jul 2021 09:42:44 +0000 (11:42 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 23 Sep 2021 13:27:25 +0000 (15:27 +0200)
Add two functions to encrement or decrement a referenc counter
attached to TX packet structure (struct quic_tx_packet). The packet are freed
when their counters reach the null value.

include/haproxy/xprt_quic-t.h
include/haproxy/xprt_quic.h

index b5e7cad53031dbfdef7596fe98d60ef6fd1d7c4e..b83c34e6e82edc4caee2f6bdfa7c78dfaefae762 100644 (file)
@@ -482,6 +482,8 @@ struct quic_tx_packet {
        struct quic_pktns *pktns;
        /* Flags. */
        unsigned int flags;
+       /* Reference counter */
+       int refcnt;
        /* Next packet in the same datagram */
        struct quic_tx_packet *next;
 };
index 92091778ffaee1c24e341cbd326b0b9888e61791..57a565bd18ca604235ed0544efbea21cd61c304d 100644 (file)
@@ -1064,6 +1064,19 @@ static inline void free_quic_rx_packet(struct quic_rx_packet *pkt)
        quic_rx_packet_refdec(pkt);
 }
 
+/* Increment the reference counter of <pkt> */
+static inline void quic_tx_packet_refinc(struct quic_tx_packet *pkt)
+{
+       HA_ATOMIC_ADD(&pkt->refcnt, 1);
+}
+
+/* Decrement the reference counter of <pkt> */
+static inline void quic_tx_packet_refdec(struct quic_tx_packet *pkt)
+{
+       if (!HA_ATOMIC_SUB_FETCH(&pkt->refcnt, 1))
+               pool_free(pool_head_quic_tx_packet, pkt);
+}
+
 ssize_t quic_lstnr_dgram_read(char *buf, size_t len, void *owner,
                               struct sockaddr_storage *saddr);
 ssize_t quic_srv_dgram_read(char *buf, size_t len, void *owner,