Skip to content

Commit cb84c37

Browse files
committed
pythongh-112070: make functools.lrucacle threadsafe in --disable-gil build
1 parent d4f83e1 commit cb84c37

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Modules/_functoolsmodule.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "pycore_object.h" // _PyObject_GC_TRACK
77
#include "pycore_pystate.h" // _PyThreadState_GET()
88
#include "pycore_tuple.h" // _PyTuple_ITEMS()
9+
#include "pycore_critical_section.h" // Py_BEGIN_CRITICAL_SECTION
910

1011

1112
#include "clinic/_functoolsmodule.c.h"
@@ -1274,7 +1275,11 @@ lru_cache_dealloc(lru_cache_object *obj)
12741275
static PyObject *
12751276
lru_cache_call(lru_cache_object *self, PyObject *args, PyObject *kwds)
12761277
{
1277-
return self->wrapper(self, args, kwds);
1278+
PyObject* result;
1279+
Py_BEGIN_CRITICAL_SECTION(self);
1280+
result = self->wrapper(self, args, kwds);
1281+
Py_END_CRITICAL_SECTION;
1282+
return result;
12781283
}
12791284

12801285
static PyObject *
@@ -1287,6 +1292,7 @@ lru_cache_descr_get(PyObject *self, PyObject *obj, PyObject *type)
12871292
}
12881293

12891294
/*[clinic input]
1295+
@critical_section
12901296
_functools._lru_cache_wrapper.cache_info
12911297
12921298
Report cache statistics
@@ -1308,6 +1314,7 @@ _functools__lru_cache_wrapper_cache_info_impl(PyObject *self)
13081314
}
13091315

13101316
/*[clinic input]
1317+
@critical_section
13111318
_functools._lru_cache_wrapper.cache_clear
13121319
13131320
Clear the cache and cache statistics

0 commit comments

Comments
 (0)