From 7c1feeaef3876edcdcb4bdbd63108702a5f0be2d Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Mon, 25 May 2026 17:12:02 +0200 Subject: [PATCH] sd: don't block other goroutines while scanning This is still a stopgap, but slightly better than what we had before. Note that `wfe` probably didn't save any battery power anyway since `wfe` doesn't work as expected when the SoftDevice is enabled. --- gap_nrf528xx-central.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gap_nrf528xx-central.go b/gap_nrf528xx-central.go index ed9fafef..1ada00cc 100644 --- a/gap_nrf528xx-central.go +++ b/gap_nrf528xx-central.go @@ -5,6 +5,7 @@ package bluetooth import ( "device/arm" "errors" + "runtime" "runtime/volatile" "time" "unsafe" @@ -58,8 +59,8 @@ func (a *Adapter) Scan(callback func(*Adapter, ScanResult)) error { for { // Wait for the next advertisement packet to arrive. // TODO: use some sort of condition variable once the scheduler supports - // them. - arm.Asm("wfe") + // them. Using Gosched() here as a stopgap to let other goroutines run. + runtime.Gosched() if gotScanReport.Get() == 0 { // Spurious event. Continue waiting. continue