From 2dc5242fc05d3074f0832c48a96d4a9e78336aa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20O=2E=20Sel=C3=A5sdal?= Date: Tue, 10 Dec 2013 01:11:31 +0100 Subject: [PATCH] Use TailQ in mbuf --- include/ucore/mbuf.h | 7 ++++--- src/mbuf.c | 3 ++- test/test_mbuf.c | 6 ++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/ucore/mbuf.h b/include/ucore/mbuf.h index bcd551d..c73cd36 100644 --- a/include/ucore/mbuf.h +++ b/include/ucore/mbuf.h @@ -2,6 +2,7 @@ #define UC_MBUF_H_ #include #include +#include "tailq.h" #ifdef __GNUC__ # define UC_INLINE inline __attribute__((always_inline)) @@ -17,9 +18,9 @@ enum UC_MBUF_FLAGS { }; struct MBuf { - /** prev/next pointer, user can use this for a linked list*/ - struct MBuf *prev; - struct MBuf *next; + /** linked list entry for keeping the mbufs in a list*/ + struct TailQ entry; + /** Pointers the user can use to remember spots in * the data. (these must either be NULL pointers or point into * something in the buffer*/ diff --git a/src/mbuf.c b/src/mbuf.c index 390630f..4dd52e1 100644 --- a/src/mbuf.c +++ b/src/mbuf.c @@ -43,13 +43,14 @@ uint8_t *uc_mbuf_pull(struct MBuf *mbuf, uint32_t size) void uc_mbuf_init(struct MBuf *mbuf, uint8_t *buf, uint32_t len, uint32_t headroom, uint32_t flags) { mbuf->bufstart = buf; - mbuf->next = NULL; mbuf->p1 = mbuf->p2 = mbuf->p3 = mbuf->p4 = NULL; mbuf->cookie = NULL; mbuf->flags = flags; mbuf->allocated = len + headroom; mbuf->head = mbuf->bufstart + headroom; mbuf->tail = mbuf->head; + mbuf->entry.next = NULL; + mbuf->entry.prev = NULL; } struct MBuf *uc_mbuf_new_hr(uint32_t len, uint32_t headroom) diff --git a/test/test_mbuf.c b/test/test_mbuf.c index 453ffc8..4a3e5b3 100644 --- a/test/test_mbuf.c +++ b/test/test_mbuf.c @@ -13,7 +13,6 @@ START_TEST (test_mbuf_new) fail_if(uc_mbuf_len(mbuf) != 0); fail_if(uc_mbuf_headroom(mbuf) != 0); fail_if(uc_mbuf_tailroom(mbuf) != 110); - fail_if(mbuf->next != NULL); fail_if(mbuf->p1 != NULL); fail_if(mbuf->p2 != NULL); fail_if(mbuf->p3 != NULL); @@ -34,7 +33,8 @@ START_TEST (test_mbuf_new_inline) fail_if(uc_mbuf_len(mbuf) != 0); fail_if(uc_mbuf_headroom(mbuf) != 0); fail_if(uc_mbuf_tailroom(mbuf) != 110); - fail_if(mbuf->next != NULL); + fail_if(mbuf->entry.next != NULL); + fail_if(mbuf->entry.prev != NULL); fail_if(mbuf->p1 != NULL); fail_if(mbuf->p2 != NULL); fail_if(mbuf->p3 != NULL); @@ -55,7 +55,6 @@ START_TEST (test_mbuf_new_headroom) fail_if(uc_mbuf_len(mbuf) != 0); fail_if(uc_mbuf_headroom(mbuf) != 20); fail_if(uc_mbuf_tailroom(mbuf) != 110); - fail_if(mbuf->next != NULL); fail_if(mbuf->p1 != NULL); fail_if(mbuf->p2 != NULL); fail_if(mbuf->p3 != NULL); @@ -228,7 +227,6 @@ START_TEST (test_mbuf_static) fail_if(uc_mbuf_len(&mbuf) != 0); fail_if(uc_mbuf_headroom(&mbuf) != 24); fail_if(uc_mbuf_tailroom(&mbuf) != 1000); - fail_if(mbuf.next != NULL); fail_if(mbuf.p1 != NULL); fail_if(mbuf.p2 != NULL); fail_if(mbuf.p3 != NULL);