diff options
| author | Robert Kuska <rkuska@gmail.com> | 2020-03-13 19:21:19 +0100 |
|---|---|---|
| committer | Ian Lance Taylor <iant@golang.org> | 2020-03-15 00:17:52 +0000 |
| commit | dad94e7c39e748a4134efc67ff9256a5addf34b7 (patch) | |
| tree | 296ea254c543fe8a7fe2c2224131d028aa9b8dfd /src/net/http/server.go | |
| parent | d774d979ddab54c5d878e31d015c0678573b7a9d (diff) | |
| download | go-dad94e7c39e748a4134efc67ff9256a5addf34b7.tar.xz | |
net/http: use atomicBool for inShutdown
This removes the TODO leftover by replacing the original int32 for
atomicBool that mimicks atomic operations for boolean.
Change-Id: I1b2cac0c9573c890c7315e9906ce6bfccee3d770
Reviewed-on: https://go-review.googlesource.com/c/go/+/223357
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/net/http/server.go')
| -rw-r--r-- | src/net/http/server.go | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/src/net/http/server.go b/src/net/http/server.go index 58aff08424..54d28d03a0 100644 --- a/src/net/http/server.go +++ b/src/net/http/server.go @@ -2577,8 +2577,9 @@ type Server struct { // value. ConnContext func(ctx context.Context, c net.Conn) context.Context + inShutdown atomicBool // true when when server is in shutdown + disableKeepAlives int32 // accessed atomically. - inShutdown int32 // accessed atomically (non-zero means we're in Shutdown) nextProtoOnce sync.Once // guards setupHTTP2_* init nextProtoErr error // result of http2.ConfigureServer if used @@ -2624,7 +2625,7 @@ func (s *Server) closeDoneChanLocked() { // Close returns any error returned from closing the Server's // underlying Listener(s). func (srv *Server) Close() error { - atomic.StoreInt32(&srv.inShutdown, 1) + srv.inShutdown.setTrue() srv.mu.Lock() defer srv.mu.Unlock() srv.closeDoneChanLocked() @@ -2666,7 +2667,7 @@ var shutdownPollInterval = 500 * time.Millisecond // Once Shutdown has been called on a server, it may not be reused; // future calls to methods such as Serve will return ErrServerClosed. func (srv *Server) Shutdown(ctx context.Context) error { - atomic.StoreInt32(&srv.inShutdown, 1) + srv.inShutdown.setTrue() srv.mu.Lock() lnerr := srv.closeListenersLocked() @@ -3032,9 +3033,7 @@ func (s *Server) doKeepAlives() bool { } func (s *Server) shuttingDown() bool { - // TODO: replace inShutdown with the existing atomicBool type; - // see https://github.com/golang/go/issues/20239#issuecomment-381434582 - return atomic.LoadInt32(&s.inShutdown) != 0 + return s.inShutdown.isSet() } // SetKeepAlivesEnabled controls whether HTTP keep-alives are enabled. |
