From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:45627) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T3rud-0007gy-90 for qemu-devel@nongnu.org; Tue, 21 Aug 2012 13:06:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T3rua-0002nK-Sq for qemu-devel@nongnu.org; Tue, 21 Aug 2012 13:06:43 -0400 Received: from mail-gg0-f173.google.com ([209.85.161.173]:58041) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T3rua-0002fG-P5 for qemu-devel@nongnu.org; Tue, 21 Aug 2012 13:06:40 -0400 Received: by mail-gg0-f173.google.com with SMTP id a5so32818ggn.4 for ; Tue, 21 Aug 2012 10:06:40 -0700 (PDT) Sender: fluxion From: Michael Roth Date: Tue, 21 Aug 2012 12:05:48 -0500 Message-Id: <1345568757-14365-15-git-send-email-mdroth@linux.vnet.ibm.com> In-Reply-To: <1345568757-14365-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1345568757-14365-1-git-send-email-mdroth@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 14/23] qlist: add qlist_size() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: aliguori@us.ibm.com Signed-off-by: Michael Roth Reviewed-by: Eric Blake Signed-off-by: Michael Roth Signed-off-by: Anthony Liguori (cherry picked from commit a86a4c2f7b7f0b72816ea1c219d8140699b6665b) Signed-off-by: Michael Roth --- qlist.c | 13 +++++++++++++ qlist.h | 1 + 2 files changed, 14 insertions(+) diff --git a/qlist.c b/qlist.c index 88498b1..b48ec5b 100644 --- a/qlist.c +++ b/qlist.c @@ -124,6 +124,19 @@ int qlist_empty(const QList *qlist) return QTAILQ_EMPTY(&qlist->head); } +static void qlist_size_iter(QObject *obj, void *opaque) +{ + size_t *count = opaque; + (*count)++; +} + +size_t qlist_size(const QList *qlist) +{ + size_t count = 0; + qlist_iter(qlist, qlist_size_iter, &count); + return count; +} + /** * qobject_to_qlist(): Convert a QObject into a QList */ diff --git a/qlist.h b/qlist.h index d426bd4..ae776f9 100644 --- a/qlist.h +++ b/qlist.h @@ -49,6 +49,7 @@ void qlist_iter(const QList *qlist, QObject *qlist_pop(QList *qlist); QObject *qlist_peek(QList *qlist); int qlist_empty(const QList *qlist); +size_t qlist_size(const QList *qlist); QList *qobject_to_qlist(const QObject *obj); static inline const QListEntry *qlist_first(const QList *qlist) -- 1.7.9.5