Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions Include/internal/pycore_interp_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,7 @@ struct _is {
Py_ssize_t sys_tracing_threads; /* Count of threads with c_tracefunc set */
PyObject *monitoring_callables[PY_MONITORING_TOOL_IDS][_PY_MONITORING_EVENTS];
PyObject *monitoring_tool_names[PY_MONITORING_TOOL_IDS];
PyMutex monitoring_tool_names_mutex;
uintptr_t monitoring_tool_versions[PY_MONITORING_TOOL_IDS];

struct _Py_interp_cached_objects cached_objects;
Expand Down
15 changes: 14 additions & 1 deletion Python/instrumentation.c
Original file line number Diff line number Diff line change
Expand Up @@ -2187,11 +2187,14 @@ monitoring_use_tool_id_impl(PyObject *module, int tool_id, PyObject *name)
return NULL;
}
PyInterpreterState *interp = _PyInterpreterState_GET();
PyMutex_Lock(&interp->monitoring_tool_names_mutex);
if (interp->monitoring_tool_names[tool_id] != NULL) {
PyErr_Format(PyExc_ValueError, "tool %d is already in use", tool_id);
PyMutex_Unlock(&interp->monitoring_tool_names_mutex);
return NULL;
}
interp->monitoring_tool_names[tool_id] = Py_NewRef(name);
PyMutex_Unlock(&interp->monitoring_tool_names_mutex);
Py_RETURN_NONE;
}

Expand All @@ -2213,11 +2216,14 @@ monitoring_clear_tool_id_impl(PyObject *module, int tool_id)

PyInterpreterState *interp = _PyInterpreterState_GET();

PyMutex_Lock(&interp->monitoring_tool_names_mutex);
if (interp->monitoring_tool_names[tool_id] != NULL) {
if (_PyMonitoring_ClearToolId(tool_id) < 0) {
PyMutex_Unlock(&interp->monitoring_tool_names_mutex);
return NULL;
}
}
PyMutex_Unlock(&interp->monitoring_tool_names_mutex);

Py_RETURN_NONE;
}
Expand All @@ -2239,13 +2245,16 @@ monitoring_free_tool_id_impl(PyObject *module, int tool_id)
}
PyInterpreterState *interp = _PyInterpreterState_GET();

PyMutex_Lock(&interp->monitoring_tool_names_mutex);
if (interp->monitoring_tool_names[tool_id] != NULL) {
if (_PyMonitoring_ClearToolId(tool_id) < 0) {
PyMutex_Unlock(&interp->monitoring_tool_names_mutex);
return NULL;
}
}

Py_CLEAR(interp->monitoring_tool_names[tool_id]);
PyMutex_Unlock(&interp->monitoring_tool_names_mutex);
Py_RETURN_NONE;
}

Expand All @@ -2267,11 +2276,15 @@ monitoring_get_tool_impl(PyObject *module, int tool_id)
return NULL;
}
PyInterpreterState *interp = _PyInterpreterState_GET();
PyMutex_Lock(&interp->monitoring_tool_names_mutex);
PyObject *name = interp->monitoring_tool_names[tool_id];
if (name == NULL) {
PyMutex_Unlock(&interp->monitoring_tool_names_mutex);
Py_RETURN_NONE;
}
return Py_NewRef(name);
PyObject *ret = Py_NewRef(name);
PyMutex_Unlock(&interp->monitoring_tool_names_mutex);
return ret;
}

/*[clinic input]
Expand Down
Loading