Received: from eggs.gnu.org ([2001:4830:134:3::10]:41507) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VaXVV-0002DE-2Y for qemu-devel@nongnu.org; Sun, 27 Oct 2013 17:04:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VaXVK-0008Oh-4u for qemu-devel@nongnu.org; Sun, 27 Oct 2013 17:04:21 -0400 Received: from mail6.webfaction.com ([74.55.86.74]:34189 helo=smtp.webfaction.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VaXVJ-0008Od-VY for qemu-devel@nongnu.org; Sun, 27 Oct 2013 17:04:10 -0400 From: Charlie Shepherd Date: Sun, 27 Oct 2013 22:03:53 +0100 Message-Id: <1382907834-21255-4-git-send-email-charlie@ctshepherd.com> In-Reply-To: <1382907834-21255-1-git-send-email-charlie@ctshepherd.com> References: <1382907834-21255-1-git-send-email-charlie@ctshepherd.com> Subject: [Qemu-devel] [PATCH v4 3/4] Introduce blocking_fn annotation List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, pbonzini@redhat.com, gabriel@kerneis.info, charlie@ctshepherd.com, stefanha@gmail.com From: Gabriel Kerneis A blocking function is a function that must not be called in coroutine context, for example because it might block for a long amount of time. This annotation should be used to mark normal functions that have a coroutine_fn counterpart, to make sure that the former is not used instead of the later in coroutine context. Signed-off-by: Gabriel Kerneis --- include/block/coroutine.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/include/block/coroutine.h b/include/block/coroutine.h index e11a587..02ce32d 100644 --- a/include/block/coroutine.h +++ b/include/block/coroutine.h @@ -54,6 +54,29 @@ */ #define coroutine_fn +/** + * Mark a function that executes in blocking context + * + * Functions that execute in blocking context cannot be called directly from + * coroutine functions. In the future it would be nice to enable compiler or + * static checker support for catching such errors. This annotation might make + * it possible and in the meantime it serves as documentation. + * + * Annotating a function as "blocking" is stronger than having a mere + * (unannotated) normal function. It means that it might block the main + * loop for a significant amount of time, and therefore must not be + * called in coroutine context. In general, its hints that an + * alternative coroutine function performing the same taks is available + * for use in coroutine context. + * + * For example: + * + * static void blocking_fn foo(void) { + * .... + * } + */ +#define blocking_fn + typedef struct Coroutine Coroutine; /** -- 1.8.4.rc3