From 168fe13784e92cc4dd5a08f21be06f4a9bd1a87f Mon Sep 17 00:00:00 2001 From: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com> Date: Tue, 6 Sep 2016 10:23:11 -0400 Subject: [PATCH] tls: remove unneeded atomic load TlsSession state holder 'state_' is loaded twice when we check for its modification in the TlsSession state machine code. std::atomic_compare_exchange_strong returns false when 'state_' is not equals to 'old_state' and in this case 'old_state' is changed for the current value of 'state_'. So reload it right after the returns is not efficient and may also have an unexpected corner case. This patch re-uses the value of 'old_state' for next processing. Change-Id: Ia29abc0f5834caabf12f1ae528ff11b132bd603c Reviewed-by: Stepan Salenikovich <stepan.salenikovich@savoirfairelinux.com> --- src/security/tls_session.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/security/tls_session.cpp b/src/security/tls_session.cpp index 75976f0bf9..09641e8e9b 100644 --- a/src/security/tls_session.cpp +++ b/src/security/tls_session.cpp @@ -778,7 +778,7 @@ TlsSession::process() // update state_ with taking care for external state change if (not std::atomic_compare_exchange_strong(&state_, &old_state, new_state)) - new_state = state_; + new_state = old_state; if (old_state != new_state and callbacks_.onStateChange) callbacks_.onStateChange(new_state); -- GitLab