From: Ian Lance Taylor Date: Sat, 12 Mar 2011 02:01:28 +0000 (-0800) Subject: net: don't loop to drain wakeup pipe. X-Git-Tag: weekly.2011-03-15~29 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=c01238a571769f12a9c2bb971d26fe27c4158530;p=gostls13.git net: don't loop to drain wakeup pipe. The loop always makes an extra system call. It only makes a difference if more than 100 goroutines started waiting for something to happen on a network file descriptor since the last time the pipe was drained, which is unlikely since we will be woken up the first time a goroutine starts waiting. If we don't drain the pipe this time, we'll be woken up again right away and can drain again. R=rsc CC=golang-dev https://golang.org/cl/4275042 --- diff --git a/src/pkg/net/fd.go b/src/pkg/net/fd.go index 2ba9296f31..ad1a7c29a9 100644 --- a/src/pkg/net/fd.go +++ b/src/pkg/net/fd.go @@ -215,10 +215,10 @@ func (s *pollServer) Run() { continue } if fd == s.pr.Fd() { - // Drain our wakeup pipe. - for nn, _ := s.pr.Read(scratch[0:]); nn > 0; { - nn, _ = s.pr.Read(scratch[0:]) - } + // Drain our wakeup pipe (we could loop here, + // but it's unlikely that there are more than + // len(scratch) wakeup calls). + s.pr.Read(scratch[0:]) // Read from channels Update: for {