mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-04 11:07:46 +00:00
fcd88356db
In the early days of TinyGo, the idea of `postinit` was to enable interrupts only after initializers have run. Which kind of makes sense... except that `time.Sleep` is allowed in init code and `time.Sleep` requires interrupts to be enabled. Therefore, interrupts must be enabled while initializers are being run. This commit simply moves the enabling of interrupts to a point right before running package initializers. It also removes `runtime.postinit`, which is not necessary anymore (and was only used on AVR).
32 lines
619 B
Go
32 lines
619 B
Go
//go:build !scheduler.none
|
|
// +build !scheduler.none
|
|
|
|
package runtime
|
|
|
|
import "internal/task"
|
|
|
|
// Pause the current task for a given time.
|
|
//go:linkname sleep time.Sleep
|
|
func sleep(duration int64) {
|
|
if duration <= 0 {
|
|
return
|
|
}
|
|
|
|
addSleepTask(task.Current(), nanosecondsToTicks(duration))
|
|
task.Pause()
|
|
}
|
|
|
|
// run is called by the program entry point to execute the go program.
|
|
// With a scheduler, init and the main function are invoked in a goroutine before starting the scheduler.
|
|
func run() {
|
|
initHeap()
|
|
go func() {
|
|
initAll()
|
|
callMain()
|
|
schedulerDone = true
|
|
}()
|
|
scheduler()
|
|
}
|
|
|
|
const hasScheduler = true
|