From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:50170) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QocB6-0001sy-Ju for qemu-devel@nongnu.org; Wed, 03 Aug 2011 10:12:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QocB2-0007sa-W2 for qemu-devel@nongnu.org; Wed, 03 Aug 2011 10:12:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33094) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QocB2-0007sP-NW for qemu-devel@nongnu.org; Wed, 03 Aug 2011 10:12:04 -0400 From: Kevin Wolf Date: Wed, 3 Aug 2011 16:14:22 +0200 Message-Id: <1312380864-15605-28-git-send-email-kwolf@redhat.com> In-Reply-To: <1312380864-15605-1-git-send-email-kwolf@redhat.com> References: <1312380864-15605-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH 27/29] coroutines: Use one global bottom half for CoQueue List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: anthony@codemonkey.ws Cc: kwolf@redhat.com, qemu-devel@nongnu.org Now that AsyncContexts don't exist any more, we can use one global bottom half for restarting coroutines instead of allocating a new one every time (before removing AsyncContexts, the problem with having a global BH was that it had to belong to a single AsyncContexts and wouldn't be executed in a different one - which leads to deadlocks) Signed-off-by: Kevin Wolf --- qemu-coroutine-lock.c | 19 ++++++------------- 1 files changed, 6 insertions(+), 13 deletions(-) diff --git a/qemu-coroutine-lock.c b/qemu-coroutine-lock.c index abaa1f7..a80f437 100644 --- a/qemu-coroutine-lock.c +++ b/qemu-coroutine-lock.c @@ -30,14 +30,10 @@ static QTAILQ_HEAD(, Coroutine) unlock_bh_queue = QTAILQ_HEAD_INITIALIZER(unlock_bh_queue); - -struct unlock_bh { - QEMUBH *bh; -}; +static QEMUBH* unlock_bh; static void qemu_co_queue_next_bh(void *opaque) { - struct unlock_bh *unlock_bh = opaque; Coroutine *next; trace_qemu_co_queue_next_bh(); @@ -45,14 +41,15 @@ static void qemu_co_queue_next_bh(void *opaque) QTAILQ_REMOVE(&unlock_bh_queue, next, co_queue_next); qemu_coroutine_enter(next, NULL); } - - qemu_bh_delete(unlock_bh->bh); - qemu_free(unlock_bh); } void qemu_co_queue_init(CoQueue *queue) { QTAILQ_INIT(&queue->entries); + + if (!unlock_bh) { + unlock_bh = qemu_bh_new(qemu_co_queue_next_bh, NULL); + } } void coroutine_fn qemu_co_queue_wait(CoQueue *queue) @@ -65,7 +62,6 @@ void coroutine_fn qemu_co_queue_wait(CoQueue *queue) bool qemu_co_queue_next(CoQueue *queue) { - struct unlock_bh *unlock_bh; Coroutine *next; next = QTAILQ_FIRST(&queue->entries); @@ -73,10 +69,7 @@ bool qemu_co_queue_next(CoQueue *queue) QTAILQ_REMOVE(&queue->entries, next, co_queue_next); QTAILQ_INSERT_TAIL(&unlock_bh_queue, next, co_queue_next); trace_qemu_co_queue_next(next); - - unlock_bh = qemu_malloc(sizeof(*unlock_bh)); - unlock_bh->bh = qemu_bh_new(qemu_co_queue_next_bh, unlock_bh); - qemu_bh_schedule(unlock_bh->bh); + qemu_bh_schedule(unlock_bh); } return (next != NULL); -- 1.7.6