|
98 | 98 | #define _Py_atomic_load_relaxed_int32(ATOMIC_VAL) _Py_atomic_load_relaxed(ATOMIC_VAL)
|
99 | 99 | #endif
|
100 | 100 |
|
| 101 | +#define HEAD_LOCK(runtime) \ |
| 102 | + PyThread_acquire_lock((runtime)->interpreters.mutex, WAIT_LOCK) |
| 103 | +#define HEAD_UNLOCK(runtime) \ |
| 104 | + PyThread_release_lock((runtime)->interpreters.mutex) |
101 | 105 |
|
102 | 106 | /* Forward declarations */
|
103 | 107 | static PyObject *trace_call_function(
|
@@ -7038,12 +7042,19 @@ PyEval_SetProfileAllThreads(Py_tracefunc func, PyObject *arg)
|
7038 | 7042 | {
|
7039 | 7043 | PyThreadState *this_tstate = _PyThreadState_GET();
|
7040 | 7044 | PyInterpreterState* interp = this_tstate->interp;
|
| 7045 | + |
| 7046 | + _PyRuntimeState *runtime = &_PyRuntime; |
| 7047 | + HEAD_LOCK(runtime); |
7041 | 7048 | PyThreadState* ts = PyInterpreterState_ThreadHead(interp);
|
| 7049 | + HEAD_UNLOCK(runtime); |
| 7050 | + |
7042 | 7051 | while (ts) {
|
7043 | 7052 | if (_PyEval_SetProfile(ts, func, arg) < 0) {
|
7044 | 7053 | _PyErr_WriteUnraisableMsg("in PyEval_SetProfileAllThreads", NULL);
|
7045 | 7054 | }
|
| 7055 | + HEAD_LOCK(runtime); |
7046 | 7056 | ts = PyThreadState_Next(ts);
|
| 7057 | + HEAD_UNLOCK(runtime); |
7047 | 7058 | }
|
7048 | 7059 | }
|
7049 | 7060 |
|
@@ -7105,12 +7116,19 @@ PyEval_SetTraceAllThreads(Py_tracefunc func, PyObject *arg)
|
7105 | 7116 | {
|
7106 | 7117 | PyThreadState *this_tstate = _PyThreadState_GET();
|
7107 | 7118 | PyInterpreterState* interp = this_tstate->interp;
|
| 7119 | + |
| 7120 | + _PyRuntimeState *runtime = &_PyRuntime; |
| 7121 | + HEAD_LOCK(runtime); |
7108 | 7122 | PyThreadState* ts = PyInterpreterState_ThreadHead(interp);
|
| 7123 | + HEAD_UNLOCK(runtime); |
| 7124 | + |
7109 | 7125 | while (ts) {
|
7110 | 7126 | if (_PyEval_SetTrace(ts, func, arg) < 0) {
|
7111 | 7127 | _PyErr_WriteUnraisableMsg("in PyEval_SetTraceAllThreads", NULL);
|
7112 | 7128 | }
|
| 7129 | + HEAD_LOCK(runtime); |
7113 | 7130 | ts = PyThreadState_Next(ts);
|
| 7131 | + HEAD_UNLOCK(runtime); |
7114 | 7132 | }
|
7115 | 7133 | }
|
7116 | 7134 |
|
|
0 commit comments