Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

py/scheduler: Allow C scheduler callbacks to re-queue themselves.#17347

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
projectgus wants to merge2 commits intomicropython:master
base:master
Choose a base branch
Loading
fromprojectgus:feature/c-scheduler-recurse
Open
Show file tree
Hide file tree
Changes fromall 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
25 changes: 25 additions & 0 deletionsports/unix/coverage.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -184,6 +184,18 @@ 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 bool coverage_sched_function_continue;

static void coverage_sched_function(mp_sched_node_t *node) {
(void)node;
mp_printf(&mp_plat_print, "scheduled function\n");
if (coverage_sched_function_continue) {
// Re-scheduling node will cause it to run again next time scheduled functions are run
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 DownExpand Up@@ -621,6 +633,19 @@ 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);

coverage_sched_function_continue = 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);
}
// Clear this flag to prevent the function scheduling itself again
coverage_sched_function_continue = false;
// Will only run the first time through this loop, then not scheduled again
for (int i = 0; i < 3; ++i) {
mp_handle_pending(true);
}
}

// ringbuf
Expand Down
1 change: 1 addition & 0 deletionsports/unix/variants/coverage/mpconfigvariant.h
View file
Open in desktop
Original file line numberDiff line numberDiff 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
4 changes: 4 additions & 0 deletionspy/scheduler.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -90,6 +90,7 @@ static inline void mp_sched_run_pending(void) {
// Run all pending C callbacks.
while (MP_STATE_VM(sched_head) != NULL) {
mp_sched_node_t *node = MP_STATE_VM(sched_head);
mp_sched_node_t *original_tail = MP_STATE_VM(sched_tail);
MP_STATE_VM(sched_head) = node->next;
if (MP_STATE_VM(sched_head) == NULL) {
MP_STATE_VM(sched_tail) = NULL;
Expand All@@ -99,6 +100,9 @@ static inline void mp_sched_run_pending(void) {
MICROPY_END_ATOMIC_SECTION(atomic_state);
callback(node);
atomic_state = MICROPY_BEGIN_ATOMIC_SECTION();
if (node == original_tail) {
break; // Don't execute any callbacks scheduled during this run
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Can this be rewritten as:

mp_sched_node_t*original_tail=MP_STATE_VM(sched_tail);while (MP_STATE_VM(sched_head)!=original_tail) {    ...}

?

}
#endif

Expand Down
7 changes: 7 additions & 0 deletionstests/ports/unix/extra_coverage.py.exp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -122,6 +122,13 @@ unlocked
KeyboardInterrupt:
KeyboardInterrupt:
10
loop
scheduled function
loop
scheduled function
loop
scheduled function
scheduled function
# ringbuf
99 0
98 1
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp