Skip to content

Small scheduler refactors #4852

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/internal/task/task_stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ func Pause() {
currentTask.state.pause()
}

//export tinygo_pause
func pause() {
//export tinygo_task_exit
func taskExit() {
// TODO: explicitly free the stack after switching back to the scheduler.
Pause()
}

Expand Down
2 changes: 1 addition & 1 deletion src/internal/task/task_stack_386.S
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ tinygo_startTask:
addl $4, %esp

// After return, exit this goroutine. This is a tail call.
jmp tinygo_pause
jmp tinygo_task_exit
.cfi_endproc

.global tinygo_swapTask
Expand Down
4 changes: 2 additions & 2 deletions src/internal/task/task_stack_amd64.S
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ tinygo_startTask:

// After return, exit this goroutine. This is a tail call.
#ifdef __MACH__
jmp _tinygo_pause
jmp _tinygo_task_exit
#else
jmp tinygo_pause
jmp tinygo_task_exit
#endif
.cfi_endproc

Expand Down
2 changes: 1 addition & 1 deletion src/internal/task/task_stack_amd64_windows.S
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ tinygo_startTask:

// After return, exit this goroutine.
// This has to be a call, not a jump, to keep the stack correctly aligned.
callq tinygo_pause
callq tinygo_task_exit

.global tinygo_swapTask
.section .text.tinygo_swapTask,"ax"
Expand Down
2 changes: 1 addition & 1 deletion src/internal/task/task_stack_arm.S
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ tinygo_startTask:
blx r4

// After return, exit this goroutine. This is a tail call.
bl tinygo_pause
bl tinygo_task_exit
.cfi_endproc
.size tinygo_startTask, .-tinygo_startTask

Expand Down
4 changes: 2 additions & 2 deletions src/internal/task/task_stack_arm64.S
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ tinygo_startTask:

// After return, exit this goroutine. This is a tail call.
#ifdef __MACH__
b _tinygo_pause
b _tinygo_task_exit
#else
b tinygo_pause
b tinygo_task_exit
#endif
.cfi_endproc
#ifndef __MACH__
Expand Down
4 changes: 2 additions & 2 deletions src/internal/task/task_stack_avr.S
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ tinygo_startTask:
// Note that they will probably not be able to run more than the main
// goroutine anyway, but this file is compiled for all AVRs so it needs to
// compile at least.
rcall tinygo_pause
rcall tinygo_task_exit
#else
// Other devices can (and must) use the regular call instruction.
call tinygo_pause
call tinygo_task_exit
#endif

.global tinygo_swapTask
Expand Down
2 changes: 1 addition & 1 deletion src/internal/task/task_stack_cortexm.S
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ tinygo_startTask:
blx r4

// After return, exit this goroutine. This is a tail call.
bl tinygo_pause
bl tinygo_task_exit
.cfi_endproc
.size tinygo_startTask, .-tinygo_startTask

Expand Down
2 changes: 1 addition & 1 deletion src/internal/task/task_stack_esp32.S
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ tinygo_startTask:
callx4 a3

// After return, exit this goroutine. This call never returns.
call4 tinygo_pause
call4 tinygo_task_exit

.section .text.tinygo_swapTask,"ax",@progbits
.global tinygo_swapTask
Expand Down
2 changes: 1 addition & 1 deletion src/internal/task/task_stack_esp8266.S
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ tinygo_startTask:
callx0 a12

// After return, exit this goroutine. This is a tail call.
call0 tinygo_pause
call0 tinygo_task_exit
.size tinygo_startTask, .-tinygo_startTask

.global tinygo_swapTask
Expand Down
2 changes: 1 addition & 1 deletion src/internal/task/task_stack_mipsx.S
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ tinygo_startTask:
nop

// After return, exit this goroutine. This is a tail call.
j tinygo_pause
j tinygo_task_exit
nop

.section .text.tinygo_swapTask
Expand Down
2 changes: 1 addition & 1 deletion src/internal/task/task_stack_tinygoriscv.S
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ tinygo_startTask:
jalr s0

// After return, exit this goroutine. This is a tail call.
tail tinygo_pause
tail tinygo_task_exit

.section .text.tinygo_swapTask
.global tinygo_swapTask
Expand Down
2 changes: 0 additions & 2 deletions src/runtime/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import "internal/task"

const schedulerDebug = false

var mainExited bool

var timerQueue *timerNode

// Simple logging, for debugging.
Expand Down
3 changes: 3 additions & 0 deletions src/runtime/scheduler_cooperative.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ const hasScheduler = true
// concurrency, it does not have parallelism.
const hasParallelism = false

// Set to true after main.main returns.
var mainExited bool

// Queues used by the scheduler.
var (
runqueue task.Queue
Expand Down
3 changes: 3 additions & 0 deletions src/runtime/scheduler_none.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ const hasScheduler = false
// No goroutines are allowed, so there's no parallelism anywhere.
const hasParallelism = false

// Set to true after main.main returns.
var mainExited bool

// run is called by the program entry point to execute the go program.
// With the "none" scheduler, init and the main function are invoked directly.
func run() {
Expand Down