Skip to content

Use the __COUNTER__ macro instead of __LINE__ #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions async/async.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
Expand Down