diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-12-09 08:32:53 -0700 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-12-09 12:24:43 -0700 |
commit | f6ef0cb3f5cf5a1605f9f154cfff05acb67a738d (patch) | |
tree | 81e6a1ec714366e9696144e0101020c15ef1b7b7 | |
parent | f869eaedbb73694816c4bfba87184e7849486675 (diff) |
libcr: Add public cr_assert_in_{coroutine,intrhandler}()
-rw-r--r-- | libcr/coroutine.c | 9 | ||||
-rw-r--r-- | libcr/include/libcr/coroutine.h | 21 |
2 files changed, 30 insertions, 0 deletions
diff --git a/libcr/coroutine.c b/libcr/coroutine.c index 70f2a05..aa23d58 100644 --- a/libcr/coroutine.c +++ b/libcr/coroutine.c @@ -764,6 +764,15 @@ cid_t cr_getcid(void) { return coroutine_running; } +void cr_assert_in_coroutine(void) { + assert(!cr_plat_is_in_intrhandler()); + assert_cid_state(coroutine_running, state == CR_RUNNING); +} + +void cr_assert_in_intrhandler(void) { + assert(cr_plat_is_in_intrhandler()); +} + /* cr_cid_info() **************************************************************/ #if CONFIG_COROUTINE_MEASURE_STACK diff --git a/libcr/include/libcr/coroutine.h b/libcr/include/libcr/coroutine.h index f6c5e14..eb5828b 100644 --- a/libcr/include/libcr/coroutine.h +++ b/libcr/include/libcr/coroutine.h @@ -164,6 +164,27 @@ bool cr_is_in_intrhandler(void); */ void cr_unpause_from_intrhandler(cid_t); +/** + * cr_assert_in_coroutine() asserts that it is being called from a + * running coroutine. + */ +#ifdef NDEBUG +#define cr_assert_in_coroutine() ((void)0) +#else +void cr_assert_in_coroutine(void); +#endif + + +/** + * cr_assert_in_intrhandler() asserts that it is being called from an + * interrupt handler. + */ +#ifdef NDEBUG +#define cr_assert_in_intrhandler() ((void)0) +#else +void cr_assert_in_intrhandler(void); +#endif + /* answering questions about coroutines ***************************************/ /* While the following are defined here unconditionally, the |