Skip to content

Commit be0427f

Browse files
committed
Lock rotatingtree's random state
1 parent b104360 commit be0427f

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

Modules/_lsprof.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,9 +1004,7 @@ _lsprof_exec(PyObject *module)
10041004

10051005
static PyModuleDef_Slot _lsprofslots[] = {
10061006
{Py_mod_exec, _lsprof_exec},
1007-
// XXX gh-103092: fix isolation.
1008-
{Py_mod_multiple_interpreters, Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED},
1009-
//{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
1007+
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
10101008
{0, NULL}
10111009
};
10121010

Modules/rotatingtree.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
#ifndef Py_BUILD_CORE_BUILTIN
2+
# define Py_BUILD_CORE_MODULE 1
3+
#endif
4+
5+
#include "Python.h"
6+
#include "pycore_lock.h"
17
#include "rotatingtree.h"
28

39
#define KEY_LOWER_THAN(key1, key2) ((char*)(key1) < (char*)(key2))
@@ -10,17 +16,20 @@
1016

1117
static unsigned int random_value = 1;
1218
static unsigned int random_stream = 0;
19+
static PyMutex random_mutex = (PyMutex){0};
1320

1421
static int
1522
randombits(int bits)
1623
{
1724
int result;
25+
PyMutex_Lock(&random_mutex);
1826
if (random_stream < (1U << bits)) {
1927
random_value *= 1082527;
2028
random_stream = random_value;
2129
}
2230
result = random_stream & ((1<<bits)-1);
2331
random_stream >>= bits;
32+
PyMutex_Unlock(&random_mutex);
2433
return result;
2534
}
2635

0 commit comments

Comments
 (0)