Add mbuf enqueue/dequeue functions
This commit is contained in:
+13
-1
@@ -181,7 +181,7 @@ uint8_t *uc_mbuf_put(struct MBuf *mbuf, uint32_t size);
|
||||
* data in the buffer, retreating the head pointer by size butes
|
||||
* You need to insert the size bytes in the returned pointer.
|
||||
*
|
||||
* @oaram size bytes to prepend to the buffer
|
||||
w* @oaram size bytes to prepend to the buffer
|
||||
* @return NULL if the mbuf does not have enough headroom
|
||||
*/
|
||||
uint8_t *uc_mbuf_push(struct MBuf *mbuf, uint32_t size);
|
||||
@@ -214,4 +214,16 @@ static UC_INLINE uint8_t *uc_mbuf_head(struct MBuf* mbuf)
|
||||
return mbuf->head;
|
||||
}
|
||||
|
||||
/** Add the mbuf at the end of the tailq.
|
||||
* This uses the tailQ entry member of the mbuf.
|
||||
*/
|
||||
void uc_mbuf_enqueue(struct MBuf *mbuf, struct TailQ *head);
|
||||
|
||||
/** Remove and return the mbuf at the start of the tailq.
|
||||
* @return the first mbuf in the queue, or NULL if ti isempty.
|
||||
*/
|
||||
struct MBuf *uc_mbuf_dequeue(struct TailQ *head);
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
+18
@@ -203,3 +203,21 @@ int uc_mbuf_extend_tailroom(struct MBuf *mbuf, uint32_t len)
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
void uc_mbuf_enqueue(struct MBuf *mbuf, struct TailQ *head)
|
||||
{
|
||||
uc_tailq_insert_tail(head, &mbuf->entry);
|
||||
}
|
||||
|
||||
struct MBuf *uc_mbuf_dequeue(struct TailQ *head)
|
||||
{
|
||||
struct TailQ *q;
|
||||
|
||||
if (uc_tailq_empty(head)) {
|
||||
return NULL;
|
||||
}
|
||||
q = UC_TAILQ_FIRST(head);
|
||||
uc_tailq_remove(q);
|
||||
|
||||
return UC_TAILQ_CONTAINER(q, struct MBuf, entry);
|
||||
}
|
||||
|
||||
@@ -297,6 +297,44 @@ START_TEST (test_mbuf_extend_tailroom_wrong_type)
|
||||
|
||||
END_TEST
|
||||
|
||||
START_TEST (test_mbuf_queue)
|
||||
struct MBuf *m1;
|
||||
struct MBuf *m2;
|
||||
struct MBuf *q;
|
||||
uint8_t *data1;
|
||||
UC_TAILQ_HEAD(head);
|
||||
|
||||
m1 = uc_mbuf_new_inline(10);
|
||||
fail_if(m1 == NULL);
|
||||
|
||||
data1 = uc_mbuf_put(m1, 10);
|
||||
fail_if(data1 == NULL);
|
||||
|
||||
strcpy((char*)data1, "123456789");
|
||||
|
||||
m2 = uc_mbuf_new_inline(10);
|
||||
fail_if(m2 == NULL);
|
||||
|
||||
data1 = uc_mbuf_put(m2, 10);
|
||||
fail_if(data1 == NULL);
|
||||
|
||||
strcpy((char*)data1, "987654321");
|
||||
|
||||
uc_mbuf_enqueue(m1, &head);
|
||||
uc_mbuf_enqueue(m2, &head);
|
||||
|
||||
q = uc_mbuf_dequeue(&head);
|
||||
fail_if(strcmp((char*)uc_mbuf_head(q), "123456789") != 0);
|
||||
|
||||
q = uc_mbuf_dequeue(&head);
|
||||
fail_if(strcmp((char*)uc_mbuf_head(q), "987654321") != 0);
|
||||
|
||||
fail_if(!uc_tailq_empty(&head));
|
||||
|
||||
uc_mbuf_free(m1);
|
||||
uc_mbuf_free(m2);
|
||||
|
||||
END_TEST
|
||||
|
||||
Suite *mbuf_suite(void)
|
||||
{
|
||||
@@ -316,6 +354,7 @@ Suite *mbuf_suite(void)
|
||||
tcase_add_test(tc, test_mbuf_static);
|
||||
tcase_add_test(tc, test_mbuf_extend_tailroom);
|
||||
tcase_add_test(tc, test_mbuf_extend_tailroom_wrong_type);
|
||||
tcase_add_test(tc, test_mbuf_queue);
|
||||
|
||||
suite_add_tcase(s, tc);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user