Skip to content

Commit fbfdaa5

Browse files
committed
fix(rp2): reset spinlocks at startup
1 parent 9db4f8f commit fbfdaa5

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/runtime/runtime_rp2.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
)
1515

1616
const numCPU = 2
17+
const numSpinlocks = 32
1718

1819
// machineTicks is provided by package machine.
1920
func machineTicks() uint64
@@ -297,6 +298,13 @@ var (
297298
futexLock = spinLock{id: 23}
298299
)
299300

301+
func resetSpinLocks() {
302+
for i := uint8(0); i < numSpinlocks; i++ {
303+
l := &spinLock{id: i}
304+
l.spinlock().Set(0)
305+
}
306+
}
307+
300308
// A hardware spinlock, one of the 32 spinlocks defined in the SIO peripheral.
301309
type spinLock struct {
302310
id uint8
@@ -357,9 +365,16 @@ func init() {
357365
machine.InitSerial()
358366
}
359367

368+
func prerun() {
369+
// Reset spinlocks before the full machineInit() so the scheduler doesn't
370+
// hang waiting for schedulerLock after a soft reset.
371+
resetSpinLocks()
372+
}
373+
360374
//export Reset_Handler
361375
func main() {
362376
preinit()
377+
prerun()
363378
run()
364379
exit(0)
365380
}

0 commit comments

Comments
 (0)