From ad5bc6a96e4b973f01113bb34fb3981000e8f4bd Mon Sep 17 00:00:00 2001 From: PunchShadow Date: Sun, 15 Aug 2021 18:39:45 +0800 Subject: [PATCH] Add aco_is_in_main_co() function To identify whether the function call is directly from main co or from non-main co, one function is added to support reveal the status. aco_gtls_co->main_co is used to identify the current status, because main_co pointer is NULL in main_co status --- aco.c | 5 +++++ aco.h | 3 +++ 2 files changed, 8 insertions(+) diff --git a/aco.c b/aco.c index 812914c..ed1555b 100644 --- a/aco.c +++ b/aco.c @@ -490,3 +490,8 @@ void aco_destroy(aco_t* co){ free(co); } } + +int aco_is_in_main_co(void){ + if(aco_gtls_co->main_co == NULL || aco_gtls_co == NULL) return 1; + else return 0; +} \ No newline at end of file diff --git a/aco.h b/aco.h index 97ea2ec..62373d3 100644 --- a/aco.h +++ b/aco.h @@ -186,6 +186,9 @@ extern __thread aco_t* aco_gtls_co; aco_attr_no_asan extern void aco_resume(aco_t* resume_co); +/* Return 1 if the function is directly called by main co; 0 is called by non-main co*/ +extern int aco_is_in_main_co(void); + //extern void aco_yield1(aco_t* yield_co); #define aco_yield1(yield_co) do { \ aco_assertptr((yield_co)); \