]> Cypherpunks.ru repositories - gostls13.git/commitdiff
syscall: try non-blocking stdio on wasip1
authorChris O'Hara <cohara87@gmail.com>
Thu, 25 May 2023 02:07:48 +0000 (12:07 +1000)
committerGopher Robot <gobot@golang.org>
Tue, 27 Jun 2023 01:09:18 +0000 (01:09 +0000)
Try to set stdio to non-blocking mode before the os package
calls NewFile for each fd. NewFile queries the non-blocking flag
but doesn't change it, even if the runtime supports non-blocking
stdio. Since WebAssembly modules are single-threaded, blocking
system calls temporarily halt execution of the module. If the
runtime supports non-blocking stdio, the Go runtime is able to
use the WASI net poller to poll for read/write readiness and is
able to schedule goroutines while waiting.

Change-Id: I1e3ce68a414e3c5960ce6a27fbfd38556e59c3dc
Reviewed-on: https://go-review.googlesource.com/c/go/+/498196
Reviewed-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
Auto-Submit: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
Reviewed-by: Achille Roussel <achille.roussel@gmail.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
src/syscall/fs_wasip1.go

index d60ab0b53eebfb473f7f95b7d394ddba8cc73208..4ad3f9610bccad30a1ea6c1eb80b58e32cb59a5e 100644 (file)
@@ -11,6 +11,20 @@ import (
        "unsafe"
 )
 
+func init() {
+       // Try to set stdio to non-blocking mode before the os package
+       // calls NewFile for each fd. NewFile queries the non-blocking flag
+       // but doesn't change it, even if the runtime supports non-blocking
+       // stdio. Since WebAssembly modules are single-threaded, blocking
+       // system calls temporarily halt execution of the module. If the
+       // runtime supports non-blocking stdio, the Go runtime is able to
+       // use the WASI net poller to poll for read/write readiness and is
+       // able to schedule goroutines while waiting.
+       SetNonblock(0, true)
+       SetNonblock(1, true)
+       SetNonblock(2, true)
+}
+
 type uintptr32 = uint32
 type size = uint32
 type fdflags = uint32