Repository navigation
builder: allow -buildmode=wasi-legacy with any scheduler #5994
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
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -130,6 +130,18 @@ func Current() *Task { | |
| return currentTask | ||
| } | ||
|
|
||
| //go:linkname blockingPanic runtime.blockingPanic | ||
| func blockingPanic() | ||
|
|
||
| // CurrentToBlock returns the goroutine that the caller is about to block. It | ||
| // panics when there is none, as in an //export function. | ||
| func CurrentToBlock() *Task { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: s/CurrentToBlock/CurrentTaskOrPanic I'm a huge fan of Kate Gregory's suggestions that if the name of a function is good enough, it doesn't need a comment. I think this is an opportunity here. |
||
| if currentTask == nil { | ||
| blockingPanic() | ||
| } | ||
| return currentTask | ||
| } | ||
|
|
||
| // Pause suspends the current task and returns to the scheduler. | ||
| // This function may only be called when running on a goroutine stack, not when running on the system stack. | ||
| func Pause() { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| //go:build !scheduler.asyncify | ||
|
|
||
| package task | ||
|
|
||
| // CurrentToBlock returns the goroutine that the caller is about to block. | ||
| func CurrentToBlock() *Task { | ||
| return Current() | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -267,7 +267,7 @@ func chanSend(ch *channel, value unsafe.Pointer, op *channelOp) { | |
| } | ||
|
|
||
| // Can't proceed. Add us to the list of senders and wait until we're awoken. | ||
| t := task.Current() | ||
| t := task.CurrentToBlock() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Modulo my comments above, given there is an implied task prefix, task.CurrentOrPanic is probably an even better name |
||
| t.SetDataUint32(chanOperationWaiting) | ||
| op.task = t | ||
| op.index = 0 | ||
|
|
@@ -351,7 +351,7 @@ func chanRecv(ch *channel, value unsafe.Pointer, op *channelOp) bool { | |
|
|
||
| // We can't proceed, so we add ourselves to the list of receivers and wait | ||
| // until we're awoken. | ||
| t := task.Current() | ||
| t := task.CurrentToBlock() | ||
| t.Ptr = value | ||
| t.SetDataUint32(chanOperationWaiting) | ||
| op.task = t | ||
|
|
@@ -602,7 +602,7 @@ func chanSelect(recvbuf unsafe.Pointer, states []chanSelectState, ops []channelO | |
| // first one to complete. Only one will successfully complete, because | ||
| // senders and receivers use a compare-and-exchange atomic operation on | ||
| // t.Data so that only one will be able to "take" this select operation. | ||
| t := task.Current() | ||
| t := task.CurrentToBlock() | ||
| t.Ptr = recvbuf | ||
| t.SetDataUint32(chanOperationWaiting) | ||
| for i, state := range states { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package main | ||
|
|
||
| import "time" | ||
|
|
||
| var result int32 | ||
|
|
||
| func main() { | ||
| done := make(chan int32) | ||
| go func() { | ||
| time.Sleep(time.Millisecond) | ||
| done <- 42 | ||
| }() | ||
| result = <-done | ||
| println("main done") | ||
| } | ||
|
|
||
| // Unlike a //go:wasmexport function, an //export function can still be called | ||
| // after main returns. | ||
| // | ||
| //export getResult | ||
| func getResult() int32 { | ||
| return result | ||
| } | ||
|
|
||
| //export sleep | ||
| func sleep() { | ||
| time.Sleep(time.Millisecond) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| main done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/goroutine/task
I'm not super sure that goroutine is a synonym for task or vice versa, but given the function returns a task, that naming makes more sense for me.