From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39596) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XEVWB-0002jm-GA for qemu-devel@nongnu.org; Mon, 04 Aug 2014 23:34:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XEVW5-0001Vh-1R for qemu-devel@nongnu.org; Mon, 04 Aug 2014 23:34:31 -0400 Received: from mail-pa0-f42.google.com ([209.85.220.42]:41829) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XEVW4-0001Vc-So for qemu-devel@nongnu.org; Mon, 04 Aug 2014 23:34:24 -0400 Received: by mail-pa0-f42.google.com with SMTP id lf10so534228pab.15 for ; Mon, 04 Aug 2014 20:34:24 -0700 (PDT) From: Ming Lei Date: Tue, 5 Aug 2014 11:33:06 +0800 Message-Id: <1407209598-2572-6-git-send-email-ming.lei@canonical.com> In-Reply-To: <1407209598-2572-1-git-send-email-ming.lei@canonical.com> References: <1407209598-2572-1-git-send-email-ming.lei@canonical.com> Subject: [Qemu-devel] [PATCH v1 05/17] garbage collector: introduced for support of bypass coroutine List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, Peter Maydell , Paolo Bonzini , Stefan Hajnoczi Cc: Kevin Wolf , Ming Lei , Fam Zheng , "Michael S. Tsirkin" In case of bypass coroutine, some buffers in stack have to convert to survive in the whole I/O submit & completion cycle. Garbase collector is one of the best data structure for this purpose, as I thought of. Signed-off-by: Ming Lei --- include/qemu/gc.h | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 include/qemu/gc.h diff --git a/include/qemu/gc.h b/include/qemu/gc.h new file mode 100644 index 0000000..b9a3f6e --- /dev/null +++ b/include/qemu/gc.h @@ -0,0 +1,56 @@ +#ifndef QEMU_GC_HEADER +#define QEMU_GC_HEADER + +#include "qemu/queue.h" + +/* simple garbage collector implementation for bypass coroutine */ + +/* internal type and helper */ +typedef struct SimpleGCNode SimpleGCNode; +struct SimpleGCNode { + void *addr; + void (*free)(void *data); + QLIST_ENTRY(SimpleGCNode) node; +}; + +static inline void simple_gc_free_one(SimpleGCNode *node) +{ + if (node->free) { + node->free(node->addr); + } else { + qemu_vfree(node->addr); + } + + g_free(node); +} + +/* public type and helpers */ +typedef struct { + QLIST_HEAD(, SimpleGCNode) head; +} SimpleGC; + +static inline void simple_gc_init(SimpleGC *gc) +{ + QLIST_INIT(&gc->head); +} + +static inline void simple_gc_add(SimpleGC *gc, void *addr, + void (*free)(void *data)) +{ + SimpleGCNode *node = g_malloc0(sizeof(*node)); + + node->addr = addr; + node->free = free; + QLIST_INSERT_HEAD(&gc->head, node, node); +} + +static inline void simple_gc_free_all(SimpleGC *gc) +{ + SimpleGCNode *curr, *next; + + QLIST_FOREACH_SAFE(curr, &gc->head, node, next) { + QLIST_REMOVE(curr, node); + simple_gc_free_one(curr); + } +} +#endif -- 1.7.9.5