From e963657e7c22b3b0be78c84ec7bec28dd0fc269b Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 14 Jul 2021 13:54:14 -0700 Subject: Set tcp endpoint state atomically PiperOrigin-RevId: 384776517 --- pkg/tcpip/transport/tcp/endpoint.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'pkg/tcpip') diff --git a/pkg/tcpip/transport/tcp/endpoint.go b/pkg/tcpip/transport/tcp/endpoint.go index 9945fdd6b..ebc88d6c3 100644 --- a/pkg/tcpip/transport/tcp/endpoint.go +++ b/pkg/tcpip/transport/tcp/endpoint.go @@ -754,7 +754,7 @@ func (e *endpoint) ResumeWork() { // // Precondition: e.mu must be held to call this method. func (e *endpoint) setEndpointState(state EndpointState) { - oldstate := EndpointState(atomic.LoadUint32(&e.state)) + oldstate := EndpointState(atomic.SwapUint32(&e.state, uint32(state))) switch state { case StateEstablished: e.stack.Stats().TCP.CurrentEstablished.Increment() @@ -771,7 +771,6 @@ func (e *endpoint) setEndpointState(state EndpointState) { e.stack.Stats().TCP.CurrentEstablished.Decrement() } } - atomic.StoreUint32(&e.state, uint32(state)) } // EndpointState returns the current state of the endpoint. -- cgit v1.2.3