Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
414cfef
Add threads.mutex member to PyInterpreState
rruuaanng Oct 16, 2024
0c815fc
Add NEWS
rruuaanng Oct 16, 2024
f5ec949
Delete Misc/NEWS.d/next/Core_and_Builtins/2024-10-16-11-07-50.gh-issu…
rruuaanng Oct 16, 2024
b595153
Change to current thread mutex
rruuaanng Oct 17, 2024
2378caa
Remove runtime variable
rruuaanng Oct 17, 2024
9cb2de0
HEAD_LOCK change to INTERP_THREAD_LOCK
rruuaanng Oct 17, 2024
afbaf04
Merge branch 'main' into _gh114940
rruuaanng Oct 17, 2024
29c4ccb
HEAD_LOCK change to INTERP_THREAD_LOCK
rruuaanng Oct 17, 2024
462f97d
HEAD_LOCK change to INTERP_THREAD_LOCK
rruuaanng Oct 18, 2024
8146b6f
Remove unused variable
rruuaanng Oct 18, 2024
74cc060
Clear unused code
rruuaanng Oct 18, 2024
f30b2b1
Change comment
rruuaanng Oct 19, 2024
8e0d324
INTERP_THREAD_LOCK rename to INTERP_HEAD_LOCK
rruuaanng Oct 19, 2024
1f488c7
INTERP_THREAD_LOCK rename to INTERP_HEAD_LOCK
rruuaanng Oct 19, 2024
c99e44e
INTERP_THREAD_LOCK rename to INTERP_HEAD_LOCK
rruuaanng Oct 19, 2024
7ad9c32
Using raw member
rruuaanng Oct 19, 2024
2131d69
Fix possible race conditions
rruuaanng Oct 19, 2024
7bf9a1c
INTERP_THREAD_LOCK rename to INTERP_HEAD_LOCK
rruuaanng Oct 19, 2024
b947bc9
Rollback to unmodified
rruuaanng Oct 20, 2024
46c2709
Use variable
rruuaanng Oct 20, 2024
3c208c2
Recover assert
rruuaanng Oct 24, 2024
2bb60d9
Add mutex for get_mimalloc_allocated_blocks
rruuaanng Oct 24, 2024
3798bed
Add mutex for get_reftotal
rruuaanng Oct 24, 2024
5dc1ced
Merge branch 'main' into _gh114940
rruuaanng Nov 2, 2024
18fbaa0
Merge branch 'main' into _gh114940
rruuaanng Nov 20, 2024
6257837
add lock to codeobject
rruuaanng Nov 20, 2024
4b9a569
clear ci warning
rruuaanng Nov 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Include/internal/pycore_interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ struct _is {
or the size specified by the THREAD_STACK_SIZE macro. */
/* Used in Python/thread.c. */
size_t stacksize;
/* The mutex lock of the current executing thread. */
PyMutex mutex;
} threads;

/* Reference to the _PyRuntime global variable. This field exists
Expand Down
5 changes: 5 additions & 0 deletions Include/internal/pycore_pystate.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,11 @@ extern int _PyOS_InterruptOccurred(PyThreadState *tstate);
#define HEAD_UNLOCK(runtime) \
PyMutex_Unlock(&(runtime)->interpreters.mutex)

#define INTERP_THREAD_LOCK(interpstate) \
PyMutex_LockFlags(&(interpstate)->threads.mutex, _Py_LOCK_DONT_DETACH)
#define INTERP_THREAD_UNLOCK(interpstate) \
PyMutex_Unlock(&(interpstate)->threads.mutex)

// Get the configuration of the current interpreter.
// The caller must hold the GIL.
// Export for test_peg_generator.
Expand Down
22 changes: 10 additions & 12 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -2341,20 +2341,19 @@ void
PyEval_SetProfileAllThreads(Py_tracefunc func, PyObject *arg)
{
PyThreadState *this_tstate = _PyThreadState_GET();
PyInterpreterState* interp = this_tstate->interp;
PyInterpreterState *interp = this_tstate->interp;

_PyRuntimeState *runtime = &_PyRuntime;
HEAD_LOCK(runtime);
INTERP_THREAD_LOCK(interp);
PyThreadState* ts = PyInterpreterState_ThreadHead(interp);
HEAD_UNLOCK(runtime);
INTERP_THREAD_UNLOCK(interp);

while (ts) {
if (_PyEval_SetProfile(ts, func, arg) < 0) {
PyErr_FormatUnraisable("Exception ignored in PyEval_SetProfileAllThreads");
}
HEAD_LOCK(runtime);
INTERP_THREAD_LOCK(interp);
ts = PyThreadState_Next(ts);
HEAD_UNLOCK(runtime);
INTERP_THREAD_UNLOCK(interp);
}
}

Expand All @@ -2372,20 +2371,19 @@ void
PyEval_SetTraceAllThreads(Py_tracefunc func, PyObject *arg)
{
PyThreadState *this_tstate = _PyThreadState_GET();
PyInterpreterState* interp = this_tstate->interp;
PyInterpreterState *interp = this_tstate->interp;

_PyRuntimeState *runtime = &_PyRuntime;
HEAD_LOCK(runtime);
INTERP_THREAD_LOCK(interp);
PyThreadState* ts = PyInterpreterState_ThreadHead(interp);
HEAD_UNLOCK(runtime);
INTERP_THREAD_UNLOCK(interp);

while (ts) {
if (_PyEval_SetTrace(ts, func, arg) < 0) {
PyErr_FormatUnraisable("Exception ignored in PyEval_SetTraceAllThreads");
}
HEAD_LOCK(runtime);
INTERP_THREAD_LOCK(interp);
ts = PyThreadState_Next(ts);
HEAD_UNLOCK(runtime);
INTERP_THREAD_UNLOCK(interp);
}
}

Expand Down
Loading