Skip to content

Commit 08a440d

Browse files
committed
espressif: Don't hold interrupts disabled a long time
.. just to prevent background tasks from running
1 parent 9164629 commit 08a440d

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

shared-module/audiomp3/MP3Decoder.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ void common_hal_audiomp3_mp3file_construct(audiomp3_mp3file_obj_t *self,
226226
}
227227

228228
void common_hal_audiomp3_mp3file_set_file(audiomp3_mp3file_obj_t *self, pyb_file_obj_t *file) {
229-
background_callback_begin_critical_section();
229+
background_callback_prevent();
230230

231231
self->file = file;
232232
f_lseek(&self->file->fp, 0);
@@ -244,7 +244,7 @@ void common_hal_audiomp3_mp3file_set_file(audiomp3_mp3file_obj_t *self, pyb_file
244244
memset(self->buffers[1], 0, MAX_BUFFER_LEN);
245245
MP3FrameInfo fi;
246246
bool result = mp3file_get_next_frame_info(self, &fi);
247-
background_callback_end_critical_section();
247+
background_callback_allow();
248248
if (!result) {
249249
mp_raise_msg(&mp_type_RuntimeError,
250250
MP_ERROR_TEXT("Failed to parse MP3 file"));
@@ -296,7 +296,7 @@ void audiomp3_mp3file_reset_buffer(audiomp3_mp3file_obj_t *self,
296296
}
297297
// We don't reset the buffer index in case we're looping and we have an odd number of buffer
298298
// loads
299-
background_callback_begin_critical_section();
299+
background_callback_prevent();
300300
f_lseek(&self->file->fp, 0);
301301
self->inbuf_offset = self->inbuf_length;
302302
self->eof = 0;
@@ -305,7 +305,7 @@ void audiomp3_mp3file_reset_buffer(audiomp3_mp3file_obj_t *self,
305305
mp3file_update_inbuf_half(self);
306306
mp3file_skip_id3v2(self);
307307
mp3file_find_sync_word(self);
308-
background_callback_end_critical_section();
308+
background_callback_allow();
309309
}
310310

311311
audioio_get_buffer_result_t audiomp3_mp3file_get_buffer(audiomp3_mp3file_obj_t *self,

supervisor/background_callback.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ void background_callback_reset(void);
8989
* bracket the section of code where this is the case. These calls nest, and
9090
* begins must be balanced with ends.
9191
*/
92-
void background_callback_begin_critical_section(void);
93-
void background_callback_end_critical_section(void);
92+
void background_callback_prevent(void);
93+
void background_callback_allow(void);
9494

9595
/*
9696
* Background callbacks may stop objects from being collected

supervisor/shared/background_callback.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,19 @@ inline bool background_callback_pending(void) {
7676
return callback_head != NULL;
7777
}
7878

79-
static bool in_background_callback;
79+
static int background_prevention_count;
80+
8081
void PLACE_IN_ITCM(background_callback_run_all)() {
8182
port_background_task();
8283
if (!background_callback_pending()) {
8384
return;
8485
}
8586
CALLBACK_CRITICAL_BEGIN;
86-
if (in_background_callback) {
87+
if (background_prevention_count) {
8788
CALLBACK_CRITICAL_END;
8889
return;
8990
}
90-
in_background_callback = true;
91+
++background_prevention_count;
9192
background_callback_t *cb = (background_callback_t *)callback_head;
9293
callback_head = NULL;
9394
callback_tail = NULL;
@@ -104,15 +105,19 @@ void PLACE_IN_ITCM(background_callback_run_all)() {
104105
CALLBACK_CRITICAL_BEGIN;
105106
cb = next;
106107
}
107-
in_background_callback = false;
108+
--background_prevention_count;
108109
CALLBACK_CRITICAL_END;
109110
}
110111

111-
void background_callback_begin_critical_section() {
112+
void background_callback_prevent() {
112113
CALLBACK_CRITICAL_BEGIN;
114+
++background_prevention_count;
115+
CALLBACK_CRITICAL_END;
113116
}
114117

115-
void background_callback_end_critical_section() {
118+
void background_callback_allow() {
119+
CALLBACK_CRITICAL_BEGIN;
120+
--background_prevention_count;
116121
CALLBACK_CRITICAL_END;
117122
}
118123

@@ -146,7 +151,7 @@ void background_callback_reset() {
146151
}
147152
callback_head = new_head;
148153
callback_tail = new_tail;
149-
in_background_callback = false;
154+
background_prevention_count = 0;
150155
CALLBACK_CRITICAL_END;
151156
}
152157

0 commit comments

Comments
 (0)