From 3d2a59d7ae2868d3ef079cbf71cee736a957e8bb Mon Sep 17 00:00:00 2001 From: christianEQ Date: Thu, 28 Jan 2021 23:17:48 +0000 Subject: [PATCH] compare_exchange in connSocketRead, explicitly enforce memory order (even if redundant) Former-commit-id: 3c4cadc020c5aa9c39a066679255b8d2520c8e22 --- src/connection.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/connection.cpp b/src/connection.cpp index 8f7c153d0..8ba75264e 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -173,7 +173,7 @@ static int connSocketWrite(connection *conn, const void *data, size_t data_len) * connected, not to mess with handler callbacks. */ ConnectionState expected = CONN_STATE_CONNECTED; - conn->state.compare_exchange_strong(expected, CONN_STATE_ERROR); + conn->state.compare_exchange_strong(expected, CONN_STATE_ERROR, std::memory_order_relaxed); } return ret; @@ -189,8 +189,8 @@ static int connSocketRead(connection *conn, void *buf, size_t buf_len) { /* Don't overwrite the state of a connection that is not already * connected, not to mess with handler callbacks. */ - if (conn->state == CONN_STATE_CONNECTED) - conn->state.store(CONN_STATE_ERROR, std::memory_order_release); + ConnectionState expected = CONN_STATE_CONNECTED; + conn->state.compare_exchange_strong(expected, CONN_STATE_ERROR, std::memory_order_release); } return ret;