mirror of
https://github.com/golang/go
synced 2024-11-21 16:54:46 -07:00
http: optimization method tryDeliver
Reduce the scope of locks and make them more standardized
This commit is contained in:
parent
2707d42966
commit
1f9db0e3c5
@ -1296,18 +1296,19 @@ func (w *wantConn) getCtxForDial() context.Context {
|
|||||||
|
|
||||||
// tryDeliver attempts to deliver pc, err to w and reports whether it succeeded.
|
// 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 {
|
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()
|
w.mu.Lock()
|
||||||
defer w.mu.Unlock()
|
defer w.mu.Unlock()
|
||||||
|
|
||||||
if w.done {
|
if w.done {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if (pc == nil) == (err == nil) {
|
|
||||||
panic("net/http: internal error: misuse of tryDeliver")
|
|
||||||
}
|
|
||||||
w.ctx = nil
|
w.ctx = nil
|
||||||
w.done = true
|
w.done = true
|
||||||
|
|
||||||
w.result <- connOrError{pc: pc, err: err, idleAt: idleAt}
|
w.result <- connOrError{pc: pc, err: err, idleAt: idleAt}
|
||||||
close(w.result)
|
close(w.result)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user