8000 py/scheduler: warning about C callbacks scheduling new tasks. by andrewleech · Pull Request #17248 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content

py/scheduler: warning about C callbacks scheduling new tasks. #17248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions ports/unix/coverage.c
Original file 8000 line number Diff line number Diff line change
Expand Up @@ -184,6 +184,17 @@ static void pairheap_test(size_t nops, int *ops) {
mp_printf(&mp_plat_print, "\n");
}

static mp_sched_node_t mp_coverage_sched_node;

static void coverage_sched_function(mp_sched_node_t *node) {
(void)node;
static mp_uint_t loop = 3;
mp_printf(&mp_plat_print, "scheduled function\n");
if (--loop) {
mp_sched_schedule_node(&mp_coverage_sched_node, coverage_sched_function);
}
}

// function to run extra tests for things that can't be checked by scripts
static mp_obj_t extra_coverage(void) {
// mp_printf (used by ports that don't have a native printf)
Expand Down Expand Up @@ -621,6 +632,12 @@ static mp_obj_t extra_coverage(void) {
mp_obj_print_exception(&mp_plat_print, MP_OBJ_FROM_PTR(nlr.ret_val));
}
mp_handle_pending(true);

mp_sched_schedule_node(&mp_coverage_sched_node, coverage_sched_function);
for (int i = 0; i <= 3; ++i) {
mp_printf(&mp_plat_print, "loop\n");
mp_handle_pending(true);
}
}

// ringbuf
Expand Down
1 change: 1 addition & 0 deletions ports/unix/variants/coverage/mpconfigvariant.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#undef MICROPY_VFS_ROM_IOCTL
#define MICROPY_VFS_ROM_IOCTL (1)
#define MICROPY_PY_CRYPTOLIB_CTR (1)
#define MICROPY_SCHEDULER_STATIC_NODES (1)

// Enable os.uname for attrtuple coverage test
#define MICROPY_PY_OS_UNAME (1)
Expand Down
2 changes: 2 additions & 0 deletions py/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ static inline void mp_sched_run_pending(void) {

#if MICROPY_SCHEDULER_STATIC_NODES
// Run all pending C callbacks.
// Warning: if C callbacks themserlves schedule new C callbacks this
// loop will never exit.
while (MP_STATE_VM(sched_head) != NULL) {
mp_sched_node_t *node = MP_STATE_VM(sched_head);
MP_STATE_VM(sched_head) = node->next;
Expand Down
7 changes: 7 additions & 0 deletions tests/ports/unix/extra_coverage.py.exp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ unlocked
KeyboardInterrupt:
KeyboardInterrupt:
10
loop
scheduled function
scheduled function
scheduled function
loop
loop
loop
# ringbuf
99 0
98 1
Expand Down
Loading
0