aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErlend E. Aasland <erlend@python.org>2024-03-12 14:44:39 +0100
committerGitHub <noreply@github.com>2024-03-12 14:44:39 +0100
commit3b7fe117fab91371f6b621e9efd02f3925f5d53b (patch)
treeced8ddf547cfb28284cd710478695802d7ca3e75
parentgh-116604: Correctly honor the gc status when calling _Py_RunGC (#116628) (diff)
downloadcpython-3b7fe117fab91371f6b621e9efd02f3925f5d53b.tar.gz
cpython-3b7fe117fab91371f6b621e9efd02f3925f5d53b.tar.bz2
cpython-3b7fe117fab91371f6b621e9efd02f3925f5d53b.zip
gh-116616: Use relaxed atomic ops to access socket module defaulttimeout (#116623)
Co-authored-by: Sam Gross <colesbury@gmail.com>
-rw-r--r--Modules/socketmodule.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index cd9a803648b..7720d59e465 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -1054,8 +1054,8 @@ init_sockobject(socket_state *state, PySocketSockObject *s,
else
#endif
{
- s->sock_timeout = state->defaulttimeout;
- if (state->defaulttimeout >= 0) {
+ s->sock_timeout = _Py_atomic_load_int64_relaxed(&state->defaulttimeout);
+ if (s->sock_timeout >= 0) {
if (internal_setblocking(s, 0) == -1) {
return -1;
}
@@ -6913,11 +6913,12 @@ static PyObject *
socket_getdefaulttimeout(PyObject *self, PyObject *Py_UNUSED(ignored))
{
socket_state *state = get_module_state(self);
- if (state->defaulttimeout < 0) {
+ PyTime_t timeout = _Py_atomic_load_int64_relaxed(&state->defaulttimeout);
+ if (timeout < 0) {
Py_RETURN_NONE;
}
else {
- double seconds = PyTime_AsSecondsDouble(state->defaulttimeout);
+ double seconds = PyTime_AsSecondsDouble(timeout);
return PyFloat_FromDouble(seconds);
}
}
@@ -6938,7 +6939,7 @@ socket_setdefaulttimeout(PyObject *self, PyObject *arg)
return NULL;
socket_state *state = get_module_state(self);
- state->defaulttimeout = timeout;
+ _Py_atomic_store_int64_relaxed(&state->defaulttimeout, timeout);
Py_RETURN_NONE;
}