8000 rp2: Use new mutex functions. · micropython/micropython@130b4a9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 130b4a9

Browse files
committed
rp2: Use new mutex functions.
Signed-off-by: Damien George <damien@micropython.org>
1 parent 94b6eb5 commit 130b4a9

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

ports/rp2/mpthreadport.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "py/mpthread.h"
3131
#include "pico/stdlib.h"
3232
#include "pico/multicore.h"
33+
#include "mutex_extra.h"
3334

3435
#if MICROPY_PY_THREAD
3536

@@ -45,34 +46,31 @@ STATIC uint32_t *core1_stack = NULL;
4546
STATIC size_t core1_stack_num_words = 0;
4647

4748
// Thread mutex.
48-
STATIC recursive_mutex_t atomic_mutex;
49-
STATIC unsigned int atomic_taken;
49+
STATIC mutex_t atomic_mutex;
5050

5151
uint32_t mp_thread_begin_atomic_section(void) {
5252
if (core1_entry) {
5353
// When both cores are executing, we also need to provide
5454
// full mutual exclusion.
55-
recursive_mutex_enter_blocking(&atomic_mutex);
56-
++atomic_taken;
55+
return mutex_enter_blocking_and_disable_interrupts(&atomic_mutex);
56+
} else {
57+
return save_and_disable_interrupts();
5758
}
58-
59-
return save_and_disable_interrupts();
6059
}
6160

6261
void mp_thread_end_atomic_section(uint32_t state) {
63-
restore_interrupts(state);
64-
65-
if (atomic_taken) {
66-
--atomic_taken;
67-
recursive_mutex_exit(&atomic_mutex);
62+
if (atomic_mutex.owner != LOCK_INVALID_OWNER_ID) {
63+
mutex_exit_and_restore_interrupts(&atomic_mutex, state);
64+
} else {
65+
restore_interrupts(state);
6866
}
6967
}
7068

7169
// Initialise threading support.
7270
void mp_thread_init(void) {
7371
assert(get_core_num() == 0);
7472

75-
recursive_mutex_init(&atomic_mutex);
73+
mutex_init(&atomic_mutex);
7674

7775
// Allow MICROPY_BEGIN_ATOMIC_SECTION to be invoked from core1.
7876
multicore_lockout_victim_init();

0 commit comments

Comments
 (0)
0