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@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));