Skip to content

Instantly share code, notes, and snippets.

@UplinkCoder
Created June 24, 2022 16:57
Show Gist options
  • Save UplinkCoder/083b4ed5a60b282b6f38e138cc2c9b93 to your computer and use it in GitHub Desktop.
Save UplinkCoder/083b4ed5a60b282b6f38e138cc2c9b93 to your computer and use it in GitHub Desktop.
#define SPWAN_TASK(RESULT, FUNC, ...) do { \
taskqueue_t* q = &CurrentWorker()->Queue; \
task_t task = {0}; \
CTX_TYPE(FUNC) ctx = {__VA_ARGS__}; \
CTX_TYPE(FUNC)* ctxPtr = &ctx; \
STATIC_ASSERT(sizeof(task._inlineContext) >= sizeof(CTX_TYPE(FUNC)), \
"Context size too large for inline context storage"); \
task.Context = task._inlineContext; \
task.TaskFunction = CAT(FUNC, Task); \
task.Parent = CurrentTask(); \
ORIGIN(task.Origin); \
(*(cast(CTX_TYPE(FUNC)*)task.Context)) = ctx; \
TaskQueue_Push(q, &task); \
WAIT_FOR(task.Parent, &task, FUNC); \
RESULT = ctxPtr->Result; \
} while(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment