From b40f0b118014f8dbc25e8ef4de82ccf78410903f Mon Sep 17 00:00:00 2001 From: qmuntal Date: Thu, 5 Feb 2026 14:57:53 +0100 Subject: [PATCH] internal/poll: simplify IOCP association checks This is a step towards deferring adding the handle to IOCP until the first IO operation. FD.pollable() obscures the fact that it is really checking if the handle is associated with the IOCP. This doesn't need to be a function that checks multiple conditions. It can be a simple boolean field that tracks whether the handle is associated with the IOCP or not. For #76391 Cq-Include-Trybots: luci.golang.try:gotip-windows-amd64-longtest,gotip-windows-amd64-race Change-Id: I3ee6532f8a387fb5cfae8ae3d20ea9569f585e71 Reviewed-on: https://go-review.googlesource.com/c/go/+/742282 Reviewed-by: Michael Pratt Reviewed-by: Alex Brainman LUCI-TryBot-Result: Go LUCI Reviewed-by: Damien Neil --- src/internal/poll/fd_windows.go | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/internal/poll/fd_windows.go b/src/internal/poll/fd_windows.go index c9e74d0699..6875557c6f 100644 --- a/src/internal/poll/fd_windows.go +++ b/src/internal/poll/fd_windows.go @@ -269,7 +269,7 @@ func (fd *FD) execIO(mode int, submit func(o *operation) (uint32, error), buf [] } }() } - if !fd.pollable() { + if !fd.associated { // If the handle is opened for overlapped IO but we can't // use the runtime poller, then we need to use an // event to wait for the IO to complete. @@ -370,7 +370,8 @@ type FD struct { // Whether FILE_FLAG_OVERLAPPED was not set when opening the file. isBlocking bool - disassociated bool + // Whether the handle is currently associated with the IOCP. + associated bool // readPinner and writePinner are automatically unpinned // before execIO returns. @@ -400,12 +401,6 @@ func (fd *FD) addOffset(off int) { fd.offset += int64(off) } -// pollable should be used instead of fd.pd.pollable(), -// as it is aware of the disassociated state. -func (fd *FD) pollable() bool { - return fd.pd.pollable() && !fd.disassociated -} - // fileKind describes the kind of file. type fileKind byte @@ -458,6 +453,7 @@ func (fd *FD) Init(net string, pollable bool) error { if err != nil { return err } + fd.associated = true // FILE_SKIP_SET_EVENT_ON_HANDLE is always safe to use. We don't use that feature // and it adds some overhead to the Windows I/O manager. @@ -490,7 +486,7 @@ func (fd *FD) DisassociateIOCP() error { } defer fd.readWriteUnlock() - if fd.isBlocking || !fd.pollable() { + if !fd.associated { // Nothing to disassociate. return nil } @@ -500,7 +496,7 @@ func (fd *FD) DisassociateIOCP() error { return err } // tryReadWriteLock means we have exclusive access to fd. - fd.disassociated = true + fd.associated = false // Don't call fd.pd.close(), it would be too racy. // There is no harm on leaving fd.pd open until Close is called. return nil -- 2.52.0