Skip to content

Commit 16bc027

Browse files
erlend-aaslandcolesbury
authored andcommitted
pythongh-116616: Use relaxed atomic ops to access socket module defaulttimeout (python#116623)
Co-authored-by: Sam Gross <colesbury@gmail.com>
1 parent bb10652 commit 16bc027

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

Modules/socketmodule.c

+6-5
Original file line numberDiff line numberDiff line change
@@ -1054,8 +1054,8 @@ init_sockobject(socket_state *state, PySocketSockObject *s,
10541054
else
10551055
#endif
10561056
{
1057-
s->sock_timeout = state->defaulttimeout;
1058-
if (state->defaulttimeout >= 0) {
1057+
s->sock_timeout = _Py_atomic_load_int64_relaxed(&state->defaulttimeout);
1058+
if (s->sock_timeout >= 0) {
10591059
if (internal_setblocking(s, 0) == -1) {
10601060
return -1;
10611061
}
@@ -6913,11 +6913,12 @@ static PyObject *
69136913
socket_getdefaulttimeout(PyObject *self, PyObject *Py_UNUSED(ignored))
69146914
{
69156915
socket_state *state = get_module_state(self);
6916-
if (state->defaulttimeout < 0) {
6916+
PyTime_t timeout = _Py_atomic_load_int64_relaxed(&state->defaulttimeout);
6917+
if (timeout < 0) {
69176918
Py_RETURN_NONE;
69186919
}
69196920
else {
6920-
double seconds = PyTime_AsSecondsDouble(state->defaulttimeout);
6921+
double seconds = PyTime_AsSecondsDouble(timeout);
69216922
return PyFloat_FromDouble(seconds);
69226923
}
69236924
}
@@ -6938,7 +6939,7 @@ socket_setdefaulttimeout(PyObject *self, PyObject *arg)
69386939
return NULL;
69396940

69406941
socket_state *state = get_module_state(self);
6941-
state->defaulttimeout = timeout;
6942+
_Py_atomic_store_int64_relaxed(&state->defaulttimeout, timeout);
69426943

69436944
Py_RETURN_NONE;
69446945
}

0 commit comments

Comments
 (0)