Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for 3.13t (free threading) #475

Merged
merged 1 commit into from
Oct 8, 2024
Merged
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
12 changes: 8 additions & 4 deletions src/viztracer/modules/snaptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ static PyObject* curr_task_getters[2] = {0};
LARGE_INTEGER qpc_freq;
#endif

#ifdef Py_NOGIL
// The "nogil" implementation of SNAPTRACE_THREAD_PROTECT_START/END uses
#ifdef Py_GIL_DISABLED
// The free threading implementation of SNAPTRACE_THREAD_PROTECT_START/END uses
// a per-tracer mutex. The mutex is acquired in SNAPTRACE_THREAD_PROTECT_START
// and released in SNAPTRACE_THREAD_PROTECT_END.
// NOTE: these macros delimit a C scope so any variables accessed after
// a SNAPTRACE_THREAD_PROTECT_END need to be declared before
// SNAPTRACE_THREAD_PROTECT_START.
#define SNAPTRACE_THREAD_PROTECT_START(self) Py_BEGIN_CRITICAL_SECTION(&self->mutex)
#define SNAPTRACE_THREAD_PROTECT_END(self) Py_END_CRITICAL_SECTION
#define SNAPTRACE_THREAD_PROTECT_START(self) Py_BEGIN_CRITICAL_SECTION(self)
#define SNAPTRACE_THREAD_PROTECT_END(self) Py_END_CRITICAL_SECTION()
#else
// The default implementation is a no-op.
#define SNAPTRACE_THREAD_PROTECT_START(self)
Expand Down Expand Up @@ -1805,6 +1805,10 @@ PyInit_snaptrace(void)
return NULL;
}

#ifdef Py_GIL_DISABLED
PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED);
#endif

Py_INCREF(&TracerType);
if (PyModule_AddObject(m, "Tracer", (PyObject*) &TracerType) < 0) {
Py_DECREF(&TracerType);
Expand Down
3 changes: 0 additions & 3 deletions src/viztracer/modules/snaptrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ typedef struct {
long buffer_size;
long buffer_head_idx;
long buffer_tail_idx;
#ifdef Py_NOGIL
PyMutex mutex;
#endif
struct MetadataNode* metadata_head;
} TracerObject;

Expand Down
4 changes: 4 additions & 0 deletions src/viztracer/modules/vcompressor/vcompressor.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,10 @@ PyInit_vcompressor(void)
return NULL;
}

#ifdef Py_GIL_DISABLED
PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED);
#endif

Py_INCREF(&VcompressorType);

if (PyModule_AddObject(m, "VCompressor", (PyObject*) &VcompressorType) < 0) {
Expand Down
Loading