Files
tinygo/src/runtime/scheduler_idle_wasip1.go
T
Jake Bailey 16fc1ea2bb runtime: make fatal failures unrecoverable
Match the Go runtime by terminating for deadlocks, stack overflows,
runtime and GC invariants, invalid lock operations, and platform
initialization failures instead of routing them through panic/recover.

Keep language-level runtime errors and unsupported user operations
recoverable. Add crash coverage that verifies fatal errors bypass deferred
recover calls.
2026-07-25 07:14:00 +02:00

33 lines
1.2 KiB
Go

//go:build wasip1 && (scheduler.tasks || scheduler.asyncify)
package runtime
// sleepTicks is the cooperative scheduler's "wait until the next deadline"
// primitive on wasip1. It is only called by the scheduler when the run queue
// is empty and there's a sleeping task or pending timer due in d ticks.
//
// If any FD waiters are registered via netpollAddWait, this routes through
// pollIO so the same poll_oneoff call observes both the clock subscription
// and the FD subscriptions. With no FD waiters it falls back to the cheap
// single-clock-subscription path.
func sleepTicks(d timeUnit) {
if pollCount > 0 {
pollIO(ticksToNanoseconds(d))
return
}
sleepTicksSubscription.u.u.timeout = uint64(d)
poll_oneoff(&sleepTicksSubscription, &sleepTicksResult, 1, &sleepTicksNEvents)
}
// waitForEvents is the cooperative scheduler's "wait until something external
// happens" primitive. It is only called when both the run queue and the
// timer/sleep queues are empty. With no FD waiters this is a genuine
// deadlock; with FD waiters we block until any of them is ready.
func waitForEvents() {
if pollCount > 0 {
pollIO(-1)
return
}
runtimeFatal("deadlocked: no event source")
}