Skip to content

Commit

Permalink
Revert "Merge SPDL_HOLD_GIL and NB_FREE_THREADED macro (#223)" (#241)
Browse files Browse the repository at this point in the history
This reverts commit fe21d11.

In Python 3.13 there are three kinds of mode

1. Built with GIL enabled
2. Built with GIL disabled, executed with GIL enabled
3. Built with GIL disabled, executed with GIL disabled

The runtime GIl is determined either by flag `-Xgil`, env var
`PYTHON_GIL`, or whether a module complied with GIL enabled is imported
or not.

So keeping a separate `SPDL_HOLD_GIL` option, allows to support all the
build modes.
  • Loading branch information
mthrok authored Oct 6, 2024
1 parent ca65d76 commit f15be66
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ option(SPDL_USE_NPPI "Enable NVIDIA 2D Image And Signal Performance Primitives s
option(SPDL_LINK_STATIC_NVJPEG "Link nvJPEG and NPPI statically." OFF)

option(SPDL_DEBUG_REFCOUNT "Enable debug print for reference counting of AVFrame objects." OFF)
option(SPDL_HOLD_GIL "Hold GIL in IO functions." OFF)
option(SPDL_BUILD_STUB "Build Python binding stub file" OFF)
option(SPDL_BUILD_PYTHON_BINDING "Build Python binding" ON)

Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def _b(var):
f"-DSPDL_USE_FFMPEG_VERSION={_SPDL_USE_FFMPEG_VERSION}",
f"-DSPDL_DEBUG_REFCOUNT={_b(_env('SPDL_DEBUG_REFCOUNT'))}",
f"-DSPDL_BUILD_STUB={_b(_SPDL_BUILD_STUB)}",
f"-DSPDL_HOLD_GIL={_b(_env('SPDL_HOLD_GIL', False))}",
###################################################################
f"-DPython_INCLUDE_DIR={sysconfig.get_paths()['include']}",
"-GNinja",
Expand Down
3 changes: 3 additions & 0 deletions src/binding/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ function(add_spdl_extension ffmpeg_version)
if (SPDL_USE_NVCODEC)
list(APPEND defs SPDL_USE_NVCODEC)
endif ()
if (SPDL_HOLD_GIL)
list(APPEND defs SPDL_HOLD_GIL)
endif ()

nanobind_add_module(${name} ${src})
target_compile_definitions(${name} PRIVATE "${defs}")
Expand Down
4 changes: 2 additions & 2 deletions src/binding/core/gil.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

#include <nanobind/nanobind.h>

#ifdef NB_FREE_THREADED
#define RELEASE_GIL() // do not release GIL in FT Python
#ifdef SPDL_HOLD_GIL
#define RELEASE_GIL()
#else
#define RELEASE_GIL() nb::gil_scoped_release __g;
#endif

0 comments on commit f15be66

Please sign in to comment.