1414
1515#include "Python.h"
1616#include "pycore_fileutils.h" // _Py_set_inheritable()
17+ #include "pycore_pyatomic_ft_wrappers.h" // FT_ATOMIC_LOAD_INT_RELAXED()
1718#include "pycore_time.h" // _PyTime_FromSecondsObject()
1819#include "pycore_tuple.h" // _PyTuple_FromPairSteal
1920
@@ -2162,7 +2163,7 @@ kqueue_queue_internal_close(kqueue_queue_Object *self)
21622163 int save_errno = 0 ;
21632164 if (self -> kqfd >= 0 ) {
21642165 int kqfd = self -> kqfd ;
2165- self -> kqfd = -1 ;
2166+ FT_ATOMIC_STORE_INT_RELAXED ( self -> kqfd , -1 ) ;
21662167 _selectstate * state = _selectstate_by_type (Py_TYPE (self ));
21672168 kqueue_tracking_remove (state , self );
21682169 Py_BEGIN_ALLOW_THREADS
@@ -2276,7 +2277,7 @@ static PyObject *
22762277kqueue_queue_get_closed (PyObject * op , void * Py_UNUSED (closure ))
22772278{
22782279 kqueue_queue_Object * self = kqueue_queue_Object_CAST (op );
2279- if (self -> kqfd < 0 ) {
2280+ if (FT_ATOMIC_LOAD_INT_RELAXED ( self -> kqfd ) < 0 ) {
22802281 Py_RETURN_TRUE ;
22812282 }
22822283 Py_RETURN_FALSE ;
@@ -2292,9 +2293,10 @@ static PyObject *
22922293select_kqueue_fileno_impl (kqueue_queue_Object * self )
22932294/*[clinic end generated code: output=716f46112a4f6e5c input=41911c539ca2b0ca]*/
22942295{
2295- if (self -> kqfd < 0 )
2296+ int kqfd = FT_ATOMIC_LOAD_INT_RELAXED (self -> kqfd );
2297+ if (kqfd < 0 )
22962298 return kqueue_queue_err_closed ();
2297- return PyLong_FromLong (self -> kqfd );
2299+ return PyLong_FromLong (kqfd );
22982300}
22992301
23002302/*[clinic input]
@@ -2349,7 +2351,7 @@ select_kqueue_control_impl(kqueue_queue_Object *self, PyObject *changelist,
23492351 PyTime_t timeout , deadline = 0 ;
23502352 _selectstate * state = _selectstate_by_type (Py_TYPE (self ));
23512353
2352- if (self -> kqfd < 0 )
2354+ if (FT_ATOMIC_LOAD_INT_RELAXED ( self -> kqfd ) < 0 )
23532355 return kqueue_queue_err_closed ();
23542356
23552357 if (maxevents < 0 ) {
@@ -2431,8 +2433,8 @@ select_kqueue_control_impl(kqueue_queue_Object *self, PyObject *changelist,
24312433 do {
24322434 Py_BEGIN_ALLOW_THREADS
24332435 errno = 0 ;
2434- gotevents = kevent (self -> kqfd , chl , nchanges ,
2435- evl , maxevents , ptimeoutspec );
2436+ gotevents = kevent (FT_ATOMIC_LOAD_INT_RELAXED ( self -> kqfd ) ,
2437+ chl , nchanges , evl , maxevents , ptimeoutspec );
24362438 Py_END_ALLOW_THREADS
24372439
24382440 if (errno != EINTR )
0 commit comments