coroutine: make cotask_cancel accept NULL pointers

This allows us to simplify (and fix) the CANCEL_TASK macro
This commit is contained in:
Andrei Alexeyev 2021-06-10 11:42:58 +03:00
parent 20afdd6c1d
commit af0efa8b1e
No known key found for this signature in database
GPG key ID: 72D26128040B9690
2 changed files with 2 additions and 3 deletions

View file

@ -610,7 +610,7 @@ static void *cotask_cancel_in_safe_context(void *arg) {
}
bool cotask_cancel(CoTask *task) {
if(cotask_status(task) == CO_STATUS_DEAD) {
if(!task || cotask_status(task) == CO_STATUS_DEAD) {
return false;
}

View file

@ -445,8 +445,7 @@ INLINE void cosched_set_invoke_target(CoSched *sched) { _cosched_global = sched;
DECLARE_EXTERN_TASK(_cancel_task_helper, { BoxedTask task; });
#define CANCEL_TASK(boxed_task) \
(boxed_task.ptr ? cotask_cancel(cotask_unbox(boxed_task)) : false)
#define CANCEL_TASK(boxed_task) cotask_cancel(cotask_unbox(boxed_task))
#define TASK_INDIRECT(iface, task) ( \
(void)COTASK_UNUSED_CHECK_##task, \