Skip to content

Commit 76af84e

Browse files
committed
fix: switch spinlock busy loop to wfe
1 parent e980135 commit 76af84e

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/runtime/runtime_rp2.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,10 @@ func coreStackTop(core uint32) uintptr {
291291

292292
// These spinlocks are needed by the runtime.
293293
var (
294-
printLock = spinLock{id: 0}
295-
schedulerLock = spinLock{id: 1}
296-
atomicsLock = spinLock{id: 2}
297-
futexLock = spinLock{id: 3}
294+
printLock = spinLock{id: 20}
295+
schedulerLock = spinLock{id: 21}
296+
atomicsLock = spinLock{id: 22}
297+
futexLock = spinLock{id: 23}
298298
)
299299

300300
// A hardware spinlock, one of the 32 spinlocks defined in the SIO peripheral.
@@ -311,15 +311,13 @@ func (l *spinLock) Lock() {
311311
// Wait for the lock to be available.
312312
spinlock := l.spinlock()
313313
for spinlock.Get() == 0 {
314-
// TODO: use wfe and send an event when unlocking so the CPU can go to
315-
// sleep while waiting for the lock.
316-
// Unfortunately when doing that, time.Sleep() seems to hang somewhere.
317-
// This needs some debugging to figure out.
314+
arm.Asm("wfe")
318315
}
319316
}
320317

321318
func (l *spinLock) Unlock() {
322319
l.spinlock().Set(0)
320+
arm.Asm("sev")
323321
}
324322

325323
// Wait until a signal is received, indicating that it can resume from the

0 commit comments

Comments
 (0)