diff options
author | Furquan Shaikh <furquan@google.com> | 2018-06-03 10:42:49 -0700 |
---|---|---|
committer | Furquan Shaikh <furquan@google.com> | 2018-06-08 23:35:54 +0000 |
commit | 7398deda2b12f2ba3ab6c14009ff8da003ef2b0c (patch) | |
tree | cd4cd66b14794474713e818b604ffc9da4caf2cb /util/sconfig | |
parent | b8a05e29ac9bf1557dd0e1f285704bb29b329ee2 (diff) | |
download | coreboot-7398deda2b12f2ba3ab6c14009ff8da003ef2b0c.tar.xz |
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
functions to dequeue element from head and peek head of a queue which
will be used in a follow-up commit.
BUG=b:80081934
TEST=Verified that abuild compiles successfully for all boards.
Change-Id: Ibd2de85b48c5d4e2790bf974ea3bb1bd387f66ee
Signed-off-by: Furquan Shaikh <furquan@google.com>
Reviewed-on: https://review.coreboot.org/26802
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Diffstat (limited to 'util/sconfig')
-rw-r--r-- | util/sconfig/main.c | 74 |
1 files changed, 62 insertions, 12 deletions
diff --git a/util/sconfig/main.c b/util/sconfig/main.c index e4c940ed68..188e7f93a2 100644 --- a/util/sconfig/main.c +++ b/util/sconfig/main.c @@ -62,11 +62,11 @@ static struct device root = { .enabled = 1 }; -static struct queue { +struct queue_entry { void *data; - struct queue *next; - struct queue *prev; -} *q; + struct queue_entry *next; + struct queue_entry *prev; +}; #define S_ALLOC(_s) s_alloc(__func__, _s) @@ -80,21 +80,22 @@ static void *s_alloc(const char *f, size_t s) return data; } -struct queue *new_queue_entry(void *data) +static struct queue_entry *new_queue_entry(void *data) { - struct queue *e = S_ALLOC(sizeof(*e)); + struct queue_entry *e = S_ALLOC(sizeof(*e)); e->data = data; e->next = e->prev = e; return e; } -void chip_enqueue_tail(void *data) +static void enqueue_tail(struct queue_entry **q_head, void *data) { - struct queue *tmp = new_queue_entry(data); + struct queue_entry *tmp = new_queue_entry(data); + struct queue_entry *q = *q_head; if (!q) { - q = tmp; + *q_head = tmp; return; } @@ -104,13 +105,19 @@ void chip_enqueue_tail(void *data) tmp->next = q; } -void *chip_dequeue_tail(void) +static void *dequeue_tail(struct queue_entry **q_head) { - struct queue *tmp = q->prev; + struct queue_entry *q = *q_head; + struct queue_entry *tmp; void *data; + if (!q) + return NULL; + + tmp = q->prev; + if (tmp == q) - q = NULL; + *q_head = NULL; else { tmp->prev->next = q; q->prev = tmp->prev; @@ -122,6 +129,49 @@ void *chip_dequeue_tail(void) return data; } +static void *dequeue_head(struct queue_entry **q_head) +{ + struct queue_entry *q = *q_head; + struct queue_entry *tmp = q; + void *data; + + if (!q) + return NULL; + + if (q->next == q) + *q_head = NULL; + else { + q->next->prev = q->prev; + q->prev->next = q->next; + *q_head = q->next; + } + + data = tmp->data; + free(tmp); + + return data; +} + +static void *peek_queue_head(struct queue_entry *q_head) +{ + if (!q_head) + return NULL; + + return q_head->data; +} + +static struct queue_entry *chip_q_head; + +void chip_enqueue_tail(void *data) +{ + enqueue_tail(&chip_q_head, data); +} + +void *chip_dequeue_tail(void) +{ + return dequeue_tail(&chip_q_head); +} + static struct device *new_dev(struct device *parent) { struct device *dev = S_ALLOC(sizeof(struct device)); |