Skip to content

Commit e72d038

Browse files
committed
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 micropython#12349. Signed-off-by: Damien George <[email protected]>
1 parent 02df2b0 commit e72d038

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

ports/esp32/mpnimbleport.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,22 @@ void mp_bluetooth_nimble_port_start(void) {
6363
void mp_bluetooth_nimble_port_shutdown(void) {
6464
DEBUG_printf("mp_bluetooth_nimble_port_shutdown\n");
6565

66+
#if MICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS_WITH_INTERLOCK
67+
// Release the GIL so any callbacks can run during the shutdown calls below.
68+
MP_THREAD_GIL_EXIT();
69+
#endif
70+
6671
// Despite the name, these is an ESP32-specific (no other NimBLE ports have these functions).
6772
// Calls ble_hs_stop() and waits for stack shutdown.
6873
nimble_port_stop();
6974

7075
// Shuts down the event queue.
7176
nimble_port_deinit();
7277

78+
#if MICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS_WITH_INTERLOCK
79+
MP_THREAD_GIL_ENTER();
80+
#endif
81+
7382
// Mark stack as shutdown.
7483
mp_bluetooth_nimble_ble_state = MP_BLUETOOTH_NIMBLE_BLE_STATE_OFF;
7584
}

0 commit comments

Comments
 (0)