summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2024-02-14 12:39:27 +1100
committerDamien George <damien@micropython.org>2024-02-16 10:51:00 +1100
commite72d03855efe4917c555a083c0fdd63819ca890f (patch)
tree45efb5c6befeb06dfd32fa80100a6d871c08df3f
parent02df2b09d4c2793ca97ad48a46640eea7945b9a1 (diff)
downloadmicropython-e72d03855efe4917c555a083c0fdd63819ca890f.tar.gz
micropython-e72d03855efe4917c555a083c0fdd63819ca890f.zip
esp32/mpnimbleport: Release the GIL while doing NimBLE port deinit.
In case callbacks must run (eg a disconnect event happens during the deinit) and the GIL must be obtained to run the callback. Fixes part of issue #12349. Signed-off-by: Damien George <damien@micropython.org>
-rw-r--r--ports/esp32/mpnimbleport.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/ports/esp32/mpnimbleport.c b/ports/esp32/mpnimbleport.c
index 8235275be6..5b57edf3c1 100644
--- a/ports/esp32/mpnimbleport.c
+++ b/ports/esp32/mpnimbleport.c
@@ -63,6 +63,11 @@ void mp_bluetooth_nimble_port_start(void) {
void mp_bluetooth_nimble_port_shutdown(void) {
DEBUG_printf("mp_bluetooth_nimble_port_shutdown\n");
+ #if MICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS_WITH_INTERLOCK
+ // Release the GIL so any callbacks can run during the shutdown calls below.
+ MP_THREAD_GIL_EXIT();
+ #endif
+
// Despite the name, these is an ESP32-specific (no other NimBLE ports have these functions).
// Calls ble_hs_stop() and waits for stack shutdown.
nimble_port_stop();
@@ -70,6 +75,10 @@ void mp_bluetooth_nimble_port_shutdown(void) {
// Shuts down the event queue.
nimble_port_deinit();
+ #if MICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS_WITH_INTERLOCK
+ MP_THREAD_GIL_ENTER();
+ #endif
+
// Mark stack as shutdown.
mp_bluetooth_nimble_ble_state = MP_BLUETOOTH_NIMBLE_BLE_STATE_OFF;
}