[coreboot-gerrit] Change in coreboot[master]: util/sconfig: Make queue handling more generic within main.c

Furquan Shaikh (Code Review) gerrit at coreboot.org
Mon Jun 4 02:49:52 CEST 2018


Furquan Shaikh has uploaded this change for review. ( https://review.coreboot.org/26802


Change subject: util/sconfig: Make queue handling more generic within main.c
......................................................................

util/sconfig: Make queue handling more generic within main.c

This change updates queue handling routines to be more generic so that
it can be used by more than just chip queue. Additionally, it provides
a function to dequeue element from head.

BUG=b:80081934
TEST=Verified that abuild compiles successfully for all boards.

Change-Id: Ibd2de85b48c5d4e2790bf974ea3bb1bd387f66ee
Signed-off-by: Furquan Shaikh <furquan at google.com>
---
M util/sconfig/main.c
1 file changed, 50 insertions(+), 8 deletions(-)



  git pull ssh://review.coreboot.org:29418/coreboot refs/changes/02/26802/1

diff --git a/util/sconfig/main.c b/util/sconfig/main.c
index 9a797a6..3bdd4d2 100644
--- a/util/sconfig/main.c
+++ b/util/sconfig/main.c
@@ -62,11 +62,11 @@
 	.enabled = 1
 };
 
-static struct queue {
+struct queue {
 	void *data;
 	struct queue *next;
 	struct queue *prev;
-} *q;
+};
 
 #define S_ALLOC(_s)	s_alloc(__func__, _s)
 
@@ -80,7 +80,7 @@
 	return data;
 }
 
-struct queue *new_queue_entry(void *data)
+static struct queue *new_queue_entry(void *data)
 {
 	struct queue *e = S_ALLOC(sizeof(*e));
 
@@ -89,12 +89,13 @@
 	return e;
 }
 
-void chip_enqueue_tail(void *data)
+static void enqueue_tail(struct queue **queue, void *data)
 {
 	struct queue *tmp = new_queue_entry(data);
+	struct queue *q = *queue;
 
 	if (!q) {
-		q = tmp;
+		q = *queue = tmp;
 		return;
 	}
 
@@ -104,13 +105,19 @@
 	tmp->next = q;
 }
 
-void *chip_dequeue_tail(void)
+static void *dequeue_tail(struct queue **queue)
 {
-	struct queue *tmp = q->prev;
+	struct queue *q = *queue;
+	struct queue *tmp;
 	void *data;
 
+	if (!q)
+		return NULL;
+
+	tmp = q->prev;
+
 	if (tmp == q)
-		q = NULL;
+		*queue = NULL;
 	else {
 		tmp->prev->next = q;
 		q->prev = tmp->prev;
@@ -122,6 +129,41 @@
 	return data;
 }
 
+static void *dequeue_head(struct queue **queue)
+{
+	struct queue *q = *queue;
+	struct queue *tmp = q;
+	void *data;
+
+	if (!q)
+		return NULL;
+
+	if (q->next == q)
+		*queue = NULL;
+	else {
+		q->next->prev = q->prev;
+		q->prev->next = q->next;
+		*queue = q->next;
+	}
+
+	data = tmp->data;
+	free(tmp);
+
+	return data;
+}
+
+static struct queue *chip_queue;
+
+void chip_enqueue_tail(void *data)
+{
+	enqueue_tail(&chip_queue, data);
+}
+
+void *chip_dequeue_tail(void)
+{
+	return dequeue_tail(&chip_queue);
+}
+
 static struct device *new_dev(struct device *parent)
 {
 	struct device *dev = S_ALLOC(sizeof(struct device));

-- 
To view, visit https://review.coreboot.org/26802
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibd2de85b48c5d4e2790bf974ea3bb1bd387f66ee
Gerrit-Change-Number: 26802
Gerrit-PatchSet: 1
Gerrit-Owner: Furquan Shaikh <furquan at google.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.coreboot.org/pipermail/coreboot-gerrit/attachments/20180604/b8e3f9cf/attachment-0001.html>


More information about the coreboot-gerrit mailing list