Skip to content

Commit d8bd26c

Browse files
authored
Merge pull request #9005 from jepler/issue8980
Postpone interacting with the web workflow if a SPI bus is locked
2 parents 3aedd90 + c0064dc commit d8bd26c

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

supervisor/shared/web_workflow/web_workflow.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@
5454
#include "shared-bindings/hashlib/Hash.h"
5555
#include "lib/oofatfs/diskio.h"
5656

57+
#if CIRCUITPY_FOURWIRE
58+
#include "shared-module/displayio/__init__.h"
59+
#endif
60+
5761
#if CIRCUITPY_MDNS
5862
#include "shared-bindings/mdns/RemoteService.h"
5963
#include "shared-bindings/mdns/Server.h"
@@ -1564,9 +1568,32 @@ static void _process_request(socketpool_socket_obj_t *socket, _request *request)
15641568
}
15651569
}
15661570

1571+
static bool supervisor_filesystem_access_could_block(void) {
1572+
#if CIRCUITPY_FOURWIRE
1573+
mp_vfs_mount_t *vfs = MP_STATE_VM(vfs_mount_table);
1574+
if (!vfs->next) {
1575+
// Assume that the CIRCUITPY root is not sharing a SPI bus with the display SPI bus
1576+
return false;
1577+
}
1578+
// Check display 0 to see if it's on a fourwire (SPI) bus. If it is, blocking is possible
1579+
// in theory other displays could block but also in reality there's generally 0 or 1 displays
1580+
for (size_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
1581+
if (display_buses[i].bus_base.type != &fourwire_fourwire_type) {
1582+
continue;
1583+
}
1584+
if (!common_hal_fourwire_fourwire_bus_free(MP_OBJ_FROM_PTR(&display_buses[i].bus_base))) {
1585+
return true;
1586+
}
1587+
}
1588+
#endif
1589+
return false;
1590+
}
15671591

15681592
void supervisor_web_workflow_background(void *data) {
1569-
while (true) {
1593+
// If "/sd" is mounted AND shared with a display, access could block.
1594+
// We don't have a good way to defer a filesystem action way down inside _process_request
1595+
// when this happens, so just postpone if there's a chance of blocking. (#8980)
1596+
while (!supervisor_filesystem_access_could_block()) {
15701597
// If we have a request in progress, continue working on it. Do this first
15711598
// so that we can accept another socket after finishing this request.
15721599
if (common_hal_socketpool_socket_get_connected(&active)) {

0 commit comments

Comments
 (0)