X-Git-Url: https://repo.jachan.dev/qemu.git/blobdiff_plain/6e855de900a4c5557816a662f412170b31b66d68..a9605e0317c7a6d5e68f3a3b6708c8ef1096f4bc:/async.c diff --git a/async.c b/async.c index 3fe70b9deb..85cc6410c5 100644 --- a/async.c +++ b/async.c @@ -24,6 +24,7 @@ #include "qemu-common.h" #include "qemu-aio.h" +#include "main-loop.h" /* Anchor of the list of Bottom Halves belonging to the context */ static struct QEMUBH *first_bh; @@ -34,16 +35,16 @@ static struct QEMUBH *first_bh; struct QEMUBH { QEMUBHFunc *cb; void *opaque; - int scheduled; - int idle; - int deleted; QEMUBH *next; + bool scheduled; + bool idle; + bool deleted; }; QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque) { QEMUBH *bh; - bh = qemu_mallocz(sizeof(QEMUBH)); + bh = g_malloc0(sizeof(QEMUBH)); bh->cb = cb; bh->opaque = opaque; bh->next = first_bh; @@ -55,6 +56,9 @@ int qemu_bh_poll(void) { QEMUBH *bh, **bhp, *next; int ret; + static int nesting = 0; + + nesting++; ret = 0; for (bh = first_bh; bh; bh = next) { @@ -68,15 +72,20 @@ int qemu_bh_poll(void) } } + nesting--; + /* remove deleted bhs */ - bhp = &first_bh; - while (*bhp) { - bh = *bhp; - if (bh->deleted) { - *bhp = bh->next; - qemu_free(bh); - } else - bhp = &bh->next; + if (!nesting) { + bhp = &first_bh; + while (*bhp) { + bh = *bhp; + if (bh->deleted) { + *bhp = bh->next; + g_free(bh); + } else { + bhp = &bh->next; + } + } } return ret; @@ -111,7 +120,7 @@ void qemu_bh_delete(QEMUBH *bh) bh->deleted = 1; } -void qemu_bh_update_timeout(int *timeout) +void qemu_bh_update_timeout(uint32_t *timeout) { QEMUBH *bh;