diff mbox

[API-NEXT,PATCHv2,2/6] linux-generic: queue: add utility functions for restructure

Message ID 1447015330-24420-3-git-send-email-bill.fischofer@linaro.org
State Superseded
Headers show

Commit Message

Bill Fischofer Nov. 8, 2015, 8:42 p.m. UTC
Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org>
---
 .../linux-generic/include/odp_queue_internal.h     | 44 ++++++++++++++++++++++
 platform/linux-generic/odp_queue.c                 |  7 ++++
 2 files changed, 51 insertions(+)
diff mbox

Patch

diff --git a/platform/linux-generic/include/odp_queue_internal.h b/platform/linux-generic/include/odp_queue_internal.h
index 6322948..32e3288 100644
--- a/platform/linux-generic/include/odp_queue_internal.h
+++ b/platform/linux-generic/include/odp_queue_internal.h
@@ -159,6 +159,50 @@  static inline int queue_prio(queue_entry_t *qe)
 	return qe->s.param.sched.prio;
 }
 
+static inline odp_buffer_hdr_t *get_buf_tail(odp_buffer_hdr_t *buf_hdr)
+{
+	odp_buffer_hdr_t *buf_tail = buf_hdr->link ? buf_hdr->link : buf_hdr;
+
+	buf_hdr->next = buf_hdr->link;
+	buf_hdr->link = NULL;
+
+	while (buf_tail->next)
+		buf_tail = buf_tail->next;
+
+	return buf_tail;
+}
+
+static inline void queue_add(queue_entry_t *queue,
+			     odp_buffer_hdr_t *buf_hdr)
+{
+	buf_hdr->next = NULL;
+
+	if (queue->s.head)
+		queue->s.tail->next = buf_hdr;
+	else
+		queue->s.head = buf_hdr;
+
+	queue->s.tail = buf_hdr;
+}
+
+static inline void queue_add_list(queue_entry_t *queue,
+				  odp_buffer_hdr_t *buf_head,
+				  odp_buffer_hdr_t *buf_tail)
+{
+	if (queue->s.head)
+		queue->s.tail->next = buf_head;
+	else
+		queue->s.head = buf_head;
+
+	queue->s.tail = buf_tail;
+}
+
+static inline void queue_add_chain(queue_entry_t *queue,
+				   odp_buffer_hdr_t *buf_hdr)
+{
+	queue_add_list(queue, buf_hdr, get_buf_tail(buf_hdr));
+}
+
 static inline void reorder_enq(queue_entry_t *queue,
 			       uint64_t order,
 			       queue_entry_t *origin_qe,
diff --git a/platform/linux-generic/odp_queue.c b/platform/linux-generic/odp_queue.c
index 2071870..bcc8190 100644
--- a/platform/linux-generic/odp_queue.c
+++ b/platform/linux-generic/odp_queue.c
@@ -69,6 +69,13 @@  static inline void get_qe_locks(queue_entry_t *qe1, queue_entry_t *qe2)
 	}
 }
 
+static inline void free_qe_locks(queue_entry_t *qe1, queue_entry_t *qe2)
+{
+	UNLOCK(&qe1->s.lock);
+	if (qe1 != qe2)
+		UNLOCK(&qe2->s.lock);
+}
+
 queue_entry_t *get_qentry(uint32_t queue_id)
 {
 	return &queue_tbl->queue[queue_id];