1
0
mirror of https://github.com/golang/go synced 2024-11-21 16:44:43 -07:00

http: optimization method tryDeliver

Reduce the scope of locks and make them more standardized
This commit is contained in:
cxlearning 2024-09-05 16:17:08 +08:00
parent 2707d42966
commit 1f9db0e3c5

View File

@ -1296,18 +1296,19 @@ func (w *wantConn) getCtxForDial() context.Context {
// tryDeliver attempts to deliver pc, err to w and reports whether it succeeded.
func (w *wantConn) tryDeliver(pc *persistConn, err error, idleAt time.Time) bool {
if (pc == nil) == (err == nil) {
panic("net/http: internal error: misuse of tryDeliver")
}
w.mu.Lock()
defer w.mu.Unlock()
if w.done {
return false
}
if (pc == nil) == (err == nil) {
panic("net/http: internal error: misuse of tryDeliver")
}
w.ctx = nil
w.done = true
w.result <- connOrError{pc: pc, err: err, idleAt: idleAt}
close(w.result)