X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=qlist.c;h=5730fb87f7bd848e2493d55bde055bf9e3965faf;hb=7006b9cff356233c3db0150ec55fd999c49dfae3;hp=ba2c66c01c1348d43e6b024c31c124f4401715a5;hpb=a6fd08eb625ae3c6a878f527270a9d384d1b04d2;p=qemu.git diff --git a/qlist.c b/qlist.c index ba2c66c01..5730fb87f 100644 --- a/qlist.c +++ b/qlist.c @@ -1,14 +1,15 @@ /* - * QList data type. + * QList Module * * Copyright (C) 2009 Red Hat Inc. * * Authors: * Luiz Capitulino * - * This work is licensed under the terms of the GNU GPL, version 2. See - * the COPYING file in the top-level directory. + * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. + * See the COPYING.LIB file in the top-level directory. */ + #include "qlist.h" #include "qobject.h" #include "qemu-queue.h" @@ -37,6 +38,23 @@ QList *qlist_new(void) return qlist; } +static void qlist_copy_elem(QObject *obj, void *opaque) +{ + QList *dst = opaque; + + qobject_incref(obj); + qlist_append_obj(dst, obj); +} + +QList *qlist_copy(QList *src) +{ + QList *dst = qlist_new(); + + qlist_iter(src, qlist_copy_elem, dst); + + return dst; +} + /** * qlist_append_obj(): Append an QObject into QList * @@ -67,6 +85,45 @@ void qlist_iter(const QList *qlist, iter(entry->value, opaque); } +QObject *qlist_pop(QList *qlist) +{ + QListEntry *entry; + QObject *ret; + + if (qlist == NULL || QTAILQ_EMPTY(&qlist->head)) { + return NULL; + } + + entry = QTAILQ_FIRST(&qlist->head); + QTAILQ_REMOVE(&qlist->head, entry, next); + + ret = entry->value; + qemu_free(entry); + + return ret; +} + +QObject *qlist_peek(QList *qlist) +{ + QListEntry *entry; + QObject *ret; + + if (qlist == NULL || QTAILQ_EMPTY(&qlist->head)) { + return NULL; + } + + entry = QTAILQ_FIRST(&qlist->head); + + ret = entry->value; + + return ret; +} + +int qlist_empty(const QList *qlist) +{ + return QTAILQ_EMPTY(&qlist->head); +} + /** * qobject_to_qlist(): Convert a QObject into a QList */