Commit 61d9cd73 authored by Ian Lance Taylor's avatar Ian Lance Taylor

internal/poll: only start Windows goroutines when we need them

We don't need to start the goroutines if the program isn't going to do
any I/O.

Fixes #19390.

Change-Id: I47eef992d3ad05ed5f3150f4d6e5b3e0cb16a551
Reviewed-on: https://go-review.googlesource.com/37762
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarAlex Brainman <alex.brainman@gmail.com>
parent 5ce06cf7
...@@ -154,6 +154,10 @@ func (s *ioSrv) ProcessRemoteIO() { ...@@ -154,6 +154,10 @@ func (s *ioSrv) ProcessRemoteIO() {
// is available. Alternatively, it passes the request onto // is available. Alternatively, it passes the request onto
// runtime netpoll and waits for completion or cancels request. // runtime netpoll and waits for completion or cancels request.
func (s *ioSrv) ExecIO(o *operation, name string, submit func(o *operation) error) (int, error) { func (s *ioSrv) ExecIO(o *operation, name string, submit func(o *operation) error) (int, error) {
if !canCancelIO {
onceStartServer.Do(startServer)
}
fd := o.fd fd := o.fd
// Notify runtime netpoll about starting IO. // Notify runtime netpoll about starting IO.
err := fd.pd.prepare(int(o.mode)) err := fd.pd.prepare(int(o.mode))
...@@ -229,21 +233,18 @@ func (s *ioSrv) ExecIO(o *operation, name string, submit func(o *operation) erro ...@@ -229,21 +233,18 @@ func (s *ioSrv) ExecIO(o *operation, name string, submit func(o *operation) erro
} }
// Start helper goroutines. // Start helper goroutines.
var rsrv, wsrv *ioSrv var rsrv, wsrv ioSrv
var onceStartServer sync.Once var onceStartServer sync.Once
func startServer() { func startServer() {
rsrv = new(ioSrv) // This is called, once, when only the CancelIo API is available.
wsrv = new(ioSrv) // Start two special goroutines, both locked to an OS thread,
if !canCancelIO { // that start and cancel IO requests.
// Only CancelIo API is available. Lets start two special goroutines // One will process read requests, while the other will do writes.
// locked to an OS thread, that both starts and cancels IO. One will rsrv.req = make(chan ioSrvReq)
// process read requests, while other will do writes. go rsrv.ProcessRemoteIO()
rsrv.req = make(chan ioSrvReq) wsrv.req = make(chan ioSrvReq)
go rsrv.ProcessRemoteIO() go wsrv.ProcessRemoteIO()
wsrv.req = make(chan ioSrvReq)
go wsrv.ProcessRemoteIO()
}
} }
// FD is a file descriptor. The net and os packages embed this type in // FD is a file descriptor. The net and os packages embed this type in
...@@ -298,7 +299,6 @@ func (fd *FD) Init(net string) (string, error) { ...@@ -298,7 +299,6 @@ func (fd *FD) Init(net string) (string, error) {
if initErr != nil { if initErr != nil {
return "", initErr return "", initErr
} }
onceStartServer.Do(startServer)
switch net { switch net {
case "file": case "file":
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment