diff options
| author | Angus Gratton <angus@redyak.com.au> | 2024-01-12 09:47:48 +1100 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2024-01-17 08:02:16 +1100 |
| commit | bdaea866b712c85d3bffaaae147c9b3470a4f896 (patch) | |
| tree | 548e19b7ac8eafd623b83ca95dcd3d33ff4d9aab | |
| parent | efa54c27b9eab3b61319e7f16d05db0ac3b6bc14 (diff) | |
rp2/mpthreadport: Make result of thread.get_ident() a non-zero integer.
CPython says thread identifier is a "nonzero integer", so rp2 should use a
1-indexed core number rather than 0-indexed. This fixes the
thread/thread_ident1 test failure on rp2 port.
Unfortunately this may be a breaking change for rp2 code which makes a
hard-coded comparison of thread identifier to 0 or 1.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
| -rw-r--r-- | ports/rp2/mpthreadport.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/ports/rp2/mpthreadport.c b/ports/rp2/mpthreadport.c index fd868329c..977df8044 100644 --- a/ports/rp2/mpthreadport.c +++ b/ports/rp2/mpthreadport.c @@ -115,9 +115,9 @@ STATIC void core1_entry_wrapper(void) { } mp_uint_t mp_thread_get_id(void) { - // On RP2, there are only two threads, one for each core, so the thread id - // is the core number. - return get_core_num(); + // On RP2, there are only two threads, one for each core. + // _thread.get_ident() must be non-zero. + return get_core_num() + 1; } mp_uint_t mp_thread_create(void *(*entry)(void *), void *arg, size_t *stack_size) { @@ -149,7 +149,7 @@ mp_uint_t mp_thread_create(void *(*entry)(void *), void *arg, size_t *stack_size // Adjust stack_size to provide room to recover from hitting the limit. *stack_size -= 512; - return 1; + return 2; // mp_thread_get_id() result for core 1 } void mp_thread_start(void) { |
