]> git.puffer.fish Git - mirror/frr.git/commitdiff
nhrpd: convert zbuf queue to DLIST
authorDavid Lamparter <equinox@diac24.net>
Sat, 27 Mar 2021 21:46:33 +0000 (22:46 +0100)
committerDavid Lamparter <equinox@opensourcerouting.org>
Tue, 19 Oct 2021 12:58:51 +0000 (14:58 +0200)
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
nhrpd/zbuf.c
nhrpd/zbuf.h

index e191a90f2d8c0bd2cdf1643f09c5d3b7753a3660..9cc2b56245ca4dd9a5405cba509bdaeb18090d8f 100644 (file)
@@ -164,35 +164,33 @@ void *zbuf_may_pull_until(struct zbuf *zb, const char *sep, struct zbuf *msg)
 void zbufq_init(struct zbuf_queue *zbq)
 {
        *zbq = (struct zbuf_queue){
-               .queue_head = LIST_INITIALIZER(zbq->queue_head),
+               .queue_head = INIT_DLIST(zbq->queue_head),
        };
 }
 
 void zbufq_reset(struct zbuf_queue *zbq)
 {
-       struct zbuf *buf, *bufn;
+       struct zbuf *buf;
 
-       list_for_each_entry_safe(buf, bufn, &zbq->queue_head, queue_list)
-       {
-               list_del(&buf->queue_list);
+       frr_each_safe (zbuf_queue, &zbq->queue_head, buf) {
+               zbuf_queue_del(&zbq->queue_head, buf);
                zbuf_free(buf);
        }
 }
 
 void zbufq_queue(struct zbuf_queue *zbq, struct zbuf *zb)
 {
-       list_add_tail(&zb->queue_list, &zbq->queue_head);
+       zbuf_queue_add_tail(&zbq->queue_head, zb);
 }
 
 int zbufq_write(struct zbuf_queue *zbq, int fd)
 {
        struct iovec iov[16];
-       struct zbuf *zb, *zbn;
+       struct zbuf *zb;
        ssize_t r;
        size_t iovcnt = 0;
 
-       list_for_each_entry_safe(zb, zbn, &zbq->queue_head, queue_list)
-       {
+       frr_each_safe (zbuf_queue, &zbq->queue_head, zb) {
                iov[iovcnt++] = (struct iovec){
                        .iov_base = zb->head, .iov_len = zbuf_used(zb),
                };
@@ -204,15 +202,14 @@ int zbufq_write(struct zbuf_queue *zbq, int fd)
        if (r < 0)
                return r;
 
-       list_for_each_entry_safe(zb, zbn, &zbq->queue_head, queue_list)
-       {
+       frr_each_safe (zbuf_queue, &zbq->queue_head, zb) {
                if (r < (ssize_t)zbuf_used(zb)) {
                        zb->head += r;
                        return 1;
                }
 
                r -= zbuf_used(zb);
-               list_del(&zb->queue_list);
+               zbuf_queue_del(&zbq->queue_head, zb);
                zbuf_free(zb);
        }
 
index 2741860bfd6d8dfdd73a8fea8ca307104c3cb4f6..d036b104608dc08a314f413fb5ada797f873966f 100644 (file)
 #include <endian.h>
 #include <sys/types.h>
 
-#include "list.h"
+#include "typesafe.h"
+
+PREDECL_DLIST(zbuf_queue);
 
 struct zbuf {
-       struct list_head queue_list;
+       struct zbuf_queue_item queue_entry;
        unsigned allocated : 1;
        unsigned error : 1;
        uint8_t *buf, *end;
        uint8_t *head, *tail;
 };
 
+DECLARE_DLIST(zbuf_queue, struct zbuf, queue_entry);
+
 struct zbuf_queue {
-       struct list_head queue_head;
+       struct zbuf_queue_head queue_head;
 };
 
 struct zbuf *zbuf_alloc(size_t size);