From 0ed0d91cdb81d0d8e6fb0ad8799b5e42aed3750a Mon Sep 17 00:00:00 2001 From: Paul Sorensen Date: Tue, 11 Jan 2022 20:22:07 -0500 Subject: [PATCH] Use the __COUNTER__ macro instead of __LINE__ This fixes the issue where a compiler puts multiple case statements on the same line and then has a conflict between the two --- async/async.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/async/async.h b/async/async.h index d22166c..7bb3e40 100644 --- a/async/async.h +++ b/async/async.h @@ -69,6 +69,11 @@ */ typedef enum ASYNC_EVT { ASYNC_INIT = 0, ASYNC_CONT = ASYNC_INIT, ASYNC_DONE = 1 } async; +/** + * Gets a unique number starting at 2 to avoid conflict with ASYNC_EVT + */ +#define _UNIQUE_NUM __COUNTER__ + 2 + /** * Declare the async state */ @@ -101,12 +106,12 @@ struct async { async_state; }; * Wait while the condition succeeds * @param cond The condition that must fail before execution can proceed */ -#define await_while(cond) *_async_k = __LINE__; case __LINE__: if (cond) return ASYNC_CONT +#define await_while(cond) *_async_k = _UNIQUE_NUM + 1; case _UNIQUE_NUM: if (cond) return ASYNC_CONT /** * Yield execution */ -#define async_yield *_async_k = __LINE__; return ASYNC_CONT; case __LINE__: +#define async_yield *_async_k = _UNIQUE_NUM + 1; return ASYNC_CONT; case _UNIQUE_NUM: /** * Exit the current async subroutine