The following commit has been merged in the master branch:
commit eb3cd7ba0b09fde59f8c0d0beca85293d4cc8617
Author: Guillem Jover <[email protected]>
Date: Sun Feb 21 05:55:17 2010 +0100
dpkg: Switch code to use “struct pkg_queue” instead of “struct pkgqueue”
The semantics of the pkq-queue module are more clear, so it makes the
code slightly easier to handle.
diff --git a/src/main.h b/src/main.h
index fb76604..869c4a1 100644
--- a/src/main.h
+++ b/src/main.h
@@ -196,16 +196,6 @@ void deferred_configure(struct pkginfo *pkg);
extern int sincenothing, dependtry;
-struct pkgqueue {
- struct pkg_list *head, **tail;
- int length;
-};
-
-#define PKGQUEUE_DEF_INIT(name) struct pkgqueue name = { NULL, &name.head, 0 }
-
-struct pkg_list *add_to_some_queue(struct pkginfo *pkg, struct pkgqueue *q);
-struct pkg_list *remove_from_some_queue(struct pkgqueue *q);
-
/* from cleanup.c (most of these are declared in archives.h) */
void cu_prermremove(int argc, void **argv);
diff --git a/src/packages.c b/src/packages.c
index d41f47f..0c1a69b 100644
--- a/src/packages.c
+++ b/src/packages.c
@@ -37,52 +37,21 @@
#include <dpkg/dpkg.h>
#include <dpkg/dpkg-db.h>
#include <dpkg/pkg-list.h>
+#include <dpkg/pkg-queue.h>
#include <dpkg/myopt.h>
#include "filesdb.h"
#include "main.h"
static struct pkginfo *progress_bytrigproc;
-static PKGQUEUE_DEF_INIT(queue);
+static struct pkg_queue queue = PKG_QUEUE_INIT;
int sincenothing = 0, dependtry = 0;
-struct pkg_list *
-add_to_some_queue(struct pkginfo *pkg, struct pkgqueue *q)
-{
- struct pkg_list *newent;
-
- newent = pkg_list_new(pkg, NULL);
-
- *q->tail = newent;
- q->tail = &newent->next;
- q->length++;
-
- return newent;
-}
-
-struct pkg_list *
-remove_from_some_queue(struct pkgqueue *q)
-{
- struct pkg_list *removeent = q->head;
-
- if (!removeent)
- return NULL;
-
- assert(q->length > 0);
-
- q->head = q->head->next;
- if (q->tail == &removeent->next)
- q->tail= &q->head;
- q->length--;
-
- return removeent;
-}
-
void
add_to_queue(struct pkginfo *pkg)
{
- add_to_some_queue(pkg, &queue);
+ pkg_queue_push(&queue, pkg);
}
void packages(const char *const *argv) {
@@ -165,7 +134,7 @@ void packages(const char *const *argv) {
}
void process_queue(void) {
- struct pkg_list *removeent, *rundown;
+ struct pkg_list *rundown;
struct pkginfo *volatile pkg;
volatile enum action action_todo;
jmp_buf ejbuf;
@@ -207,10 +176,8 @@ void process_queue(void) {
}
}
- while ((removeent = remove_from_some_queue(&queue))) {
- pkg= removeent->pkg;
- free(removeent);
-
+ while (!pkg_queue_is_empty(&queue)) {
+ pkg = pkg_queue_pop(&queue);
if (!pkg) continue; /* duplicate, which we removed earlier */
action_todo = cipaction->arg;
diff --git a/src/trigproc.c b/src/trigproc.c
index be94164..155f464 100644
--- a/src/trigproc.c
+++ b/src/trigproc.c
@@ -31,6 +31,7 @@
#include <dpkg/i18n.h>
#include <dpkg/dpkg.h>
#include <dpkg/dpkg-db.h>
+#include <dpkg/pkg-queue.h>
#include "main.h"
#include "filesdb.h"
@@ -84,7 +85,7 @@
/*========== deferred trigger queue ==========*/
-static PKGQUEUE_DEF_INIT(deferred);
+static struct pkg_queue deferred = PKG_QUEUE_INIT;
static void
trigproc_enqueue_deferred(struct pkginfo *pend)
@@ -94,22 +95,21 @@ trigproc_enqueue_deferred(struct pkginfo *pend)
ensure_package_clientdata(pend);
if (pend->clientdata->trigprocdeferred)
return;
- pend->clientdata->trigprocdeferred = add_to_some_queue(pend, &deferred);
+ pend->clientdata->trigprocdeferred = pkg_queue_push(&deferred, pend);
debug(dbg_triggers, "trigproc_enqueue_deferred pend=%s", pend->name);
}
void
trigproc_run_deferred(void)
{
- struct pkg_list *node;
- struct pkginfo *pkg;
-
debug(dbg_triggers, "trigproc_run_deferred");
- while ((node = remove_from_some_queue(&deferred))) {
- pkg = node->pkg;
- free(node);
+ while (!pkg_queue_is_empty(&deferred)) {
+ struct pkginfo *pkg;
+
+ pkg = pkg_queue_pop(&deferred);
if (!pkg)
continue;
+
pkg->clientdata->trigprocdeferred = NULL;
trigproc(pkg);
}
--
dpkg's main repository
--
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]