@@ -261,6 +261,7 @@ inline bool IsNamedTupleClass(const py::handle &type) {
261261 static read_write_mutex mutex{};
262262
263263 {
264+ const py::gil_scoped_release_simple gil_release{};
264265 const scoped_read_lock lock{mutex};
265266 const auto it = cache.find (type);
266267 if (it != cache.end ()) [[likely]] {
@@ -270,8 +271,10 @@ inline bool IsNamedTupleClass(const py::handle &type) {
270271
271272 const bool result = EVALUATE_WITH_LOCK_HELD (IsNamedTupleClassImpl (type), type);
272273 {
274+ const py::gil_scoped_release_simple gil_release{};
273275 const scoped_write_lock lock{mutex};
274276 if (cache.size () < MAX_TYPE_CACHE_SIZE) [[likely]] {
277+ const py::gil_scoped_acquire_simple gil_acquire{};
275278 cache.emplace (type, result);
276279 (void )py::weakref (type, py::cpp_function ([type](py::handle weakref) -> void {
277280 const scoped_write_lock lock{mutex};
@@ -363,6 +366,7 @@ inline bool IsStructSequenceClass(const py::handle &type) {
363366 static read_write_mutex mutex{};
364367
365368 {
369+ const py::gil_scoped_release_simple gil_release{};
366370 const scoped_read_lock lock{mutex};
367371 const auto it = cache.find (type);
368372 if (it != cache.end ()) [[likely]] {
@@ -372,8 +376,10 @@ inline bool IsStructSequenceClass(const py::handle &type) {
372376
373377 const bool result = EVALUATE_WITH_LOCK_HELD (IsStructSequenceClassImpl (type), type);
374378 {
379+ const py::gil_scoped_release_simple gil_release{};
375380 const scoped_write_lock lock{mutex};
376381 if (cache.size () < MAX_TYPE_CACHE_SIZE) [[likely]] {
382+ const py::gil_scoped_acquire_simple gil_acquire{};
377383 cache.emplace (type, result);
378384 (void )py::weakref (type, py::cpp_function ([type](py::handle weakref) -> void {
379385 const scoped_write_lock lock{mutex};
@@ -446,17 +452,21 @@ inline py::tuple StructSequenceGetFields(const py::handle &object) {
446452 static read_write_mutex mutex{};
447453
448454 {
455+ const py::gil_scoped_release_simple gil_release{};
449456 const scoped_read_lock lock{mutex};
450457 const auto it = cache.find (type);
451458 if (it != cache.end ()) [[likely]] {
459+ const py::gil_scoped_acquire_simple gil_acquire{};
452460 return py::reinterpret_borrow<py::tuple>(it->second );
453461 }
454462 }
455463
456464 const py::tuple fields = EVALUATE_WITH_LOCK_HELD (StructSequenceGetFieldsImpl (type), type);
457465 {
466+ const py::gil_scoped_release_simple gil_release{};
458467 const scoped_write_lock lock{mutex};
459468 if (cache.size () < MAX_TYPE_CACHE_SIZE) [[likely]] {
469+ const py::gil_scoped_acquire_simple gil_acquire{};
460470 cache.emplace (type, fields);
461471 fields.inc_ref ();
462472 (void )py::weakref (type, py::cpp_function ([type](py::handle weakref) -> void {
0 commit comments