Skip to content

Commit 44acdbf

Browse files
committed
ports/unix: Use 'mp_thread_init_state()' instead of own function.
The function 'mp_thread_init_state()' has been added to 'py/runtime.h' with commit #bc424dd in micropython/micropython: 'py/modthread: Move thread state initialisation to shared function.' So use that function instead of defining own function in 'ports/unix/mpbtstackport_usb.c'. Signed-off-by: Yasmin Bosch <[email protected]>
1 parent e7d4cd3 commit 44acdbf

File tree

1 file changed

+5
-42
lines changed

1 file changed

+5
-42
lines changed

ports/unix/mpbtstackport_usb.c

Lines changed: 5 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -134,45 +134,6 @@ void mp_bluetooth_btstack_port_deinit(void) {
134134
DEBUG_printf("mp_bluetooth_btstack_port_deinit: end\n");
135135
}
136136

137-
//
138-
// This function is to be called from a system thread which is not a MicroPython thread.
139-
// It sets up the relevant MicroPython state and obtains the GIL, to synchronize with the
140-
// rest of the runtime.
141-
//
142-
// The function was extracted from invoke_irq_handler() in extmod/modbluetooth.c.
143-
//
144-
// ts:
145-
// Pointer to a mp_state_thread_t that holds the state.
146-
//
147-
// stack_limit:
148-
// Value that will be used for mp_stack_set_limit().
149-
//
150-
static void init_mp_state_thread(mp_state_thread_t *ts, mp_uint_t stack_limit) {
151-
152-
mp_thread_set_state(ts);
153-
mp_stack_set_top(ts + 1); // need to include ts in root-pointer scan
154-
mp_stack_set_limit(stack_limit);
155-
ts->gc_lock_depth = 0;
156-
ts->nlr_jump_callback_top = NULL;
157-
ts->mp_pending_exception = MP_OBJ_NULL;
158-
mp_locals_set(mp_state_ctx.thread.dict_locals); // set from the outer context
159-
mp_globals_set(mp_state_ctx.thread.dict_globals); // set from the outer context
160-
MP_THREAD_GIL_ENTER();
161-
}
162-
163-
//
164-
// This function is to be called after mp_blutooth_init_mp_state_thread() before
165-
// ending the thread.
166-
// It gives back the GIL and resets the MicroPython state.
167-
//
168-
// The function was extracted from invoke_irq_handler() in extmod/modbluetooth.c.
169-
//
170-
static void deinit_mp_state_thread() {
171-
172-
MP_THREAD_GIL_EXIT();
173-
mp_thread_set_state(NULL);
174-
}
175-
176137
static void *btstack_thread(void *arg) {
177138
(void)arg;
178139

@@ -184,7 +145,8 @@ static void *btstack_thread(void *arg) {
184145
// to synchronised with the rest of the runtime.
185146

186147
mp_state_thread_t ts;
187-
init_mp_state_thread(&ts, 40000 * (sizeof(void *) / 4) - 1024);
148+
mp_thread_init_state(&ts, 40000 * (sizeof(void *) / 4) - 1024, NULL, NULL);
149+
MP_THREAD_GIL_ENTER();
188150

189151
log_info("btstack_thread: HCI_POWER_ON");
190152
hci_power_control(HCI_POWER_ON);
@@ -193,8 +155,9 @@ static void *btstack_thread(void *arg) {
193155

194156
log_info("btstack_thread: end");
195157

196-
// reset the MicroPython state
197-
deinit_mp_state_thread();
158+
// Give back the GIL and reset the MicroPython state.
159+
MP_THREAD_GIL_EXIT();
160+
mp_thread_set_state(NULL);
198161

199162
return NULL;
200163
}

0 commit comments

Comments
 (0)