Skip to content

Commit 813de30

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

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/runtime/runtime_rp2.go

Lines changed: 12 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
@@ -360,6 +369,9 @@ func init() {
360369
//export Reset_Handler
361370
func main() {
362371
preinit()
372+
// Reset spinlocks so the scheduler doesn't hang waiting for a lock after
373+
// a soft reset.
374+
resetSpinLocks()
363375
run()
364376
exit(0)
365377
}

0 commit comments

Comments
 (0)