Skip to content

Commit 13e41f4

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

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/runtime/runtime_rp2.go

Lines changed: 16 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,14 @@ var (
297298
futexLock = spinLock{id: 23}
298299
)
299300

301+
func resetSpinLocks() {
302+
l := &spinLock{id: 0}
303+
for i := uint8(0); i < numSpinlocks; i++ {
304+
l.id = i
305+
l.spinlock().Set(0)
306+
}
307+
}
308+
300309
// A hardware spinlock, one of the 32 spinlocks defined in the SIO peripheral.
301310
type spinLock struct {
302311
id uint8
@@ -357,9 +366,16 @@ func init() {
357366
machine.InitSerial()
358367
}
359368

369+
func prerun() {
370+
// Reset spinlocks before the full machineInit() so the scheduler doesn't
371+
// hang waiting for schedulerLock after a soft reset.
372+
resetSpinLocks()
373+
}
374+
360375
//export Reset_Handler
361376
func main() {
362377
preinit()
378+
prerun()
363379
run()
364380
exit(0)
365381
}

0 commit comments

Comments
 (0)