From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58407) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YL8GE-0003LL-0T for qemu-devel@nongnu.org; Tue, 10 Feb 2015 05:41:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YL8GD-0001TD-3O for qemu-devel@nongnu.org; Tue, 10 Feb 2015 05:41:41 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49589) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YL8GC-0001Sv-Rl for qemu-devel@nongnu.org; Tue, 10 Feb 2015 05:41:41 -0500 From: Kevin Wolf Date: Tue, 10 Feb 2015 11:41:27 +0100 Message-Id: <1423564888-14933-3-git-send-email-kwolf@redhat.com> In-Reply-To: <1423564888-14933-1-git-send-email-kwolf@redhat.com> References: <1423564888-14933-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH 2/3] coroutine: Clean up qemu_coroutine_enter() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, pbonzini@redhat.com, famz@redhat.com, wu.wubin@huawei.com, stefanha@redhat.com qemu_coroutine_enter() is now the only user of coroutine_swap(). Both functions are short, so inline it. Also, using COROUTINE_YIELD is now even more confusing because this code is never called during qemu_coroutine_yield() any more. In fact, this value is never read back, so we can just introduce a new COROUTINE_ENTER which documents the purpose of the task switch better. Signed-off-by: Kevin Wolf --- include/block/coroutine_int.h | 1 + qemu-coroutine.c | 36 +++++++++++++++--------------------- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/include/block/coroutine_int.h b/include/block/coroutine_int.h index f133d65..69b83db 100644 --- a/include/block/coroutine_int.h +++ b/include/block/coroutine_int.h @@ -29,6 +29,7 @@ #include "block/coroutine.h" typedef enum { + COROUTINE_ENTER = 0, COROUTINE_YIELD = 1, COROUTINE_TERMINATE = 2, } CoroutineAction; diff --git a/qemu-coroutine.c b/qemu-coroutine.c index 5019b81..c17a92b 100644 --- a/qemu-coroutine.c +++ b/qemu-coroutine.c @@ -99,29 +99,10 @@ static void coroutine_delete(Coroutine *co) qemu_coroutine_delete(co); } -static void coroutine_swap(Coroutine *from, Coroutine *to) -{ - CoroutineAction ret; - - ret = qemu_coroutine_switch(from, to, COROUTINE_YIELD); - - qemu_co_queue_run_restart(to); - - switch (ret) { - case COROUTINE_YIELD: - return; - case COROUTINE_TERMINATE: - trace_qemu_coroutine_terminate(to); - coroutine_delete(to); - return; - default: - abort(); - } -} - void qemu_coroutine_enter(Coroutine *co, void *opaque) { Coroutine *self = qemu_coroutine_self(); + CoroutineAction ret; trace_qemu_coroutine_enter(self, co, opaque); @@ -132,7 +113,20 @@ void qemu_coroutine_enter(Coroutine *co, void *opaque) co->caller = self; co->entry_arg = opaque; - coroutine_swap(self, co); + ret = qemu_coroutine_switch(self, co, COROUTINE_ENTER); + + qemu_co_queue_run_restart(co); + + switch (ret) { + case COROUTINE_YIELD: + return; + case COROUTINE_TERMINATE: + trace_qemu_coroutine_terminate(co); + coroutine_delete(co); + return; + default: + abort(); + } } void coroutine_fn qemu_coroutine_yield(void) -- 1.8.3.1