coroutine: add NOT_NULL_OR_DIE() convenience macro
Returns its argument if it's not a NULL pointer, otherwise cancels the running task.
This commit is contained in:
parent
4e55d445f8
commit
993bef8a2a
1 changed files with 9 additions and 0 deletions
|
@ -496,6 +496,15 @@ DECLARE_EXTERN_TASK(_cancel_task_helper, { BoxedTask task; });
|
|||
#define STALL cotask_wait(INT_MAX)
|
||||
#define AWAIT_SUBTASKS cotask_wait_subtasks()
|
||||
|
||||
#define NOT_NULL_OR_DIE(expr) ({ \
|
||||
__auto_type _not_null_ptr = (expr); \
|
||||
if(_not_null_ptr == NULL) { \
|
||||
cotask_cancel(NOT_NULL(cotask_active())); \
|
||||
UNREACHABLE; \
|
||||
} \
|
||||
NOT_NULL(_not_null_ptr); \
|
||||
})
|
||||
|
||||
// first arg of the generated function needs to be the ent, because ENT_UNBOXED_DISPATCH_FUNCTION dispatches on first arg.
|
||||
#define _cotask_emit_bindfunc(typename, ...) \
|
||||
INLINE typename *_cotask_bind_to_entity_##typename(typename *ent, CoTask *task) { \
|
||||
|
|
Loading…
Reference in a new issue