Use TailQ in mbuf
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
#define UC_MBUF_H_
|
#define UC_MBUF_H_
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include "tailq.h"
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
# define UC_INLINE inline __attribute__((always_inline))
|
# define UC_INLINE inline __attribute__((always_inline))
|
||||||
@@ -17,9 +18,9 @@ enum UC_MBUF_FLAGS {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct MBuf {
|
struct MBuf {
|
||||||
/** prev/next pointer, user can use this for a linked list*/
|
/** linked list entry for keeping the mbufs in a list*/
|
||||||
struct MBuf *prev;
|
struct TailQ entry;
|
||||||
struct MBuf *next;
|
|
||||||
/** Pointers the user can use to remember spots in
|
/** Pointers the user can use to remember spots in
|
||||||
* the data. (these must either be NULL pointers or point into
|
* the data. (these must either be NULL pointers or point into
|
||||||
* something in the buffer*/
|
* something in the buffer*/
|
||||||
|
|||||||
+2
-1
@@ -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)
|
void uc_mbuf_init(struct MBuf *mbuf, uint8_t *buf, uint32_t len, uint32_t headroom, uint32_t flags)
|
||||||
{
|
{
|
||||||
mbuf->bufstart = buf;
|
mbuf->bufstart = buf;
|
||||||
mbuf->next = NULL;
|
|
||||||
mbuf->p1 = mbuf->p2 = mbuf->p3 = mbuf->p4 = NULL;
|
mbuf->p1 = mbuf->p2 = mbuf->p3 = mbuf->p4 = NULL;
|
||||||
mbuf->cookie = NULL;
|
mbuf->cookie = NULL;
|
||||||
mbuf->flags = flags;
|
mbuf->flags = flags;
|
||||||
mbuf->allocated = len + headroom;
|
mbuf->allocated = len + headroom;
|
||||||
mbuf->head = mbuf->bufstart + headroom;
|
mbuf->head = mbuf->bufstart + headroom;
|
||||||
mbuf->tail = mbuf->head;
|
mbuf->tail = mbuf->head;
|
||||||
|
mbuf->entry.next = NULL;
|
||||||
|
mbuf->entry.prev = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct MBuf *uc_mbuf_new_hr(uint32_t len, uint32_t headroom)
|
struct MBuf *uc_mbuf_new_hr(uint32_t len, uint32_t headroom)
|
||||||
|
|||||||
+2
-4
@@ -13,7 +13,6 @@ START_TEST (test_mbuf_new)
|
|||||||
fail_if(uc_mbuf_len(mbuf) != 0);
|
fail_if(uc_mbuf_len(mbuf) != 0);
|
||||||
fail_if(uc_mbuf_headroom(mbuf) != 0);
|
fail_if(uc_mbuf_headroom(mbuf) != 0);
|
||||||
fail_if(uc_mbuf_tailroom(mbuf) != 110);
|
fail_if(uc_mbuf_tailroom(mbuf) != 110);
|
||||||
fail_if(mbuf->next != NULL);
|
|
||||||
fail_if(mbuf->p1 != NULL);
|
fail_if(mbuf->p1 != NULL);
|
||||||
fail_if(mbuf->p2 != NULL);
|
fail_if(mbuf->p2 != NULL);
|
||||||
fail_if(mbuf->p3 != 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_len(mbuf) != 0);
|
||||||
fail_if(uc_mbuf_headroom(mbuf) != 0);
|
fail_if(uc_mbuf_headroom(mbuf) != 0);
|
||||||
fail_if(uc_mbuf_tailroom(mbuf) != 110);
|
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->p1 != NULL);
|
||||||
fail_if(mbuf->p2 != NULL);
|
fail_if(mbuf->p2 != NULL);
|
||||||
fail_if(mbuf->p3 != 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_len(mbuf) != 0);
|
||||||
fail_if(uc_mbuf_headroom(mbuf) != 20);
|
fail_if(uc_mbuf_headroom(mbuf) != 20);
|
||||||
fail_if(uc_mbuf_tailroom(mbuf) != 110);
|
fail_if(uc_mbuf_tailroom(mbuf) != 110);
|
||||||
fail_if(mbuf->next != NULL);
|
|
||||||
fail_if(mbuf->p1 != NULL);
|
fail_if(mbuf->p1 != NULL);
|
||||||
fail_if(mbuf->p2 != NULL);
|
fail_if(mbuf->p2 != NULL);
|
||||||
fail_if(mbuf->p3 != 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_len(&mbuf) != 0);
|
||||||
fail_if(uc_mbuf_headroom(&mbuf) != 24);
|
fail_if(uc_mbuf_headroom(&mbuf) != 24);
|
||||||
fail_if(uc_mbuf_tailroom(&mbuf) != 1000);
|
fail_if(uc_mbuf_tailroom(&mbuf) != 1000);
|
||||||
fail_if(mbuf.next != NULL);
|
|
||||||
fail_if(mbuf.p1 != NULL);
|
fail_if(mbuf.p1 != NULL);
|
||||||
fail_if(mbuf.p2 != NULL);
|
fail_if(mbuf.p2 != NULL);
|
||||||
fail_if(mbuf.p3 != NULL);
|
fail_if(mbuf.p3 != NULL);
|
||||||
|
|||||||
Reference in New Issue
Block a user