99
1010#pragma once
1111
12- #include " detail/common.h "
12+ #if defined(PYBIND11_SIMPLE_GIL_MANAGEMENT)
1313
14- #include < cassert>
14+ # include " detail/common.h"
15+ # include " gil_simple.h"
1516
16- #if !defined(PYBIND11_SIMPLE_GIL_MANAGEMENT)
17+ PYBIND11_NAMESPACE_BEGIN (PYBIND11_NAMESPACE)
18+
19+ using gil_scoped_acquire = gil_scoped_acquire_simple;
20+ using gil_scoped_release = gil_scoped_release_simple;
21+
22+ PYBIND11_NAMESPACE_END (PYBIND11_NAMESPACE)
23+
24+ #else
25+
26+ # include " detail/common.h"
1727# include " detail/internals.h"
18- #endif
28+
29+ # include < cassert>
1930
2031PYBIND11_NAMESPACE_BEGIN (PYBIND11_NAMESPACE)
2132
@@ -26,8 +37,6 @@ PyThreadState *get_thread_state_unchecked();
2637
2738PYBIND11_NAMESPACE_END (detail)
2839
29- #if !defined(PYBIND11_SIMPLE_GIL_MANAGEMENT)
30-
3140/* The functions below essentially reproduce the PyGILState_* API using a RAII
3241 * pattern, but there are a few important differences:
3342 *
@@ -182,34 +191,6 @@ class gil_scoped_release {
182191 bool active = true ;
183192};
184193
185- #else // PYBIND11_SIMPLE_GIL_MANAGEMENT
186-
187- class gil_scoped_acquire {
188- PyGILState_STATE state;
189-
190- public:
191- gil_scoped_acquire () : state{PyGILState_Ensure ()} {}
192- gil_scoped_acquire (const gil_scoped_acquire &) = delete ;
193- gil_scoped_acquire &operator =(const gil_scoped_acquire &) = delete ;
194- ~gil_scoped_acquire () { PyGILState_Release (state); }
195- void disarm () {}
196- };
197-
198- class gil_scoped_release {
199- PyThreadState *state;
200-
201- public:
202- // PRECONDITION: The GIL must be held when this constructor is called.
203- gil_scoped_release () {
204- assert (PyGILState_Check ());
205- state = PyEval_SaveThread ();
206- }
207- gil_scoped_release (const gil_scoped_release &) = delete ;
208- gil_scoped_release &operator =(const gil_scoped_release &) = delete ;
209- ~gil_scoped_release () { PyEval_RestoreThread (state); }
210- void disarm () {}
211- };
212-
213- #endif // PYBIND11_SIMPLE_GIL_MANAGEMENT
214-
215194PYBIND11_NAMESPACE_END (PYBIND11_NAMESPACE)
195+
196+ #endif // !PYBIND11_SIMPLE_GIL_MANAGEMENT
0 commit comments