Skip to content

Commit

Permalink
runtime: remove minSched hack for wasm
Browse files Browse the repository at this point in the history
I am not entirely sure what it's doing (it seems related to js.FuncOf),
but tests still seem to pass when this code is removed. So let's remove
it.
  • Loading branch information
aykevl authored and deadprogram committed Oct 19, 2024
1 parent cd2bb83 commit 2f9e39e
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 39 deletions.
7 changes: 0 additions & 7 deletions src/runtime/runtime_wasm_js.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@ package runtime

type timeUnit float64 // time in milliseconds, just like Date.now() in JavaScript

// wasmNested is used to detect scheduler nesting (WASM calls into JS calls back into WASM).
// When this happens, we need to use a reduced version of the scheduler.
//
// TODO: this variable can probably be removed once //go:wasmexport is the only
// allowed way to export a wasm function (currently, //export also works).
var wasmNested bool

var handleEvent func()

//go:linkname setEventHandler syscall/js.setEventHandler
Expand Down
14 changes: 0 additions & 14 deletions src/runtime/runtime_wasm_js_scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,10 @@ func resume() {
handleEvent()
}()

if wasmNested {
minSched()
return
}

wasmNested = true
scheduler(false)
wasmNested = false
}

//export go_scheduler
func go_scheduler() {
if wasmNested {
minSched()
return
}

wasmNested = true
scheduler(false)
wasmNested = false
}
18 changes: 0 additions & 18 deletions src/runtime/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,24 +247,6 @@ func scheduler(returnAtDeadlock bool) {
}
}

// This horrible hack exists to make WASM work properly.
// When a WASM program calls into JS which calls back into WASM, the event with which we called back in needs to be handled before returning.
// Thus there are two copies of the scheduler running at once.
// This is a reduced version of the scheduler which does not deal with the timer queue (that is a problem for the outer scheduler).
func minSched() {
scheduleLog("start nested scheduler")
for !schedulerDone {
t := runqueue.Pop()
if t == nil {
break
}

scheduleLogTask(" run:", t)
t.Resume()
}
scheduleLog("stop nested scheduler")
}

func Gosched() {
runqueue.Push(task.Current())
task.Pause()
Expand Down

0 comments on commit 2f9e39e

Please sign in to comment.