9
9
10
10
#pragma once
11
11
12
- #include " detail/common.h "
12
+ #if defined(PYBIND11_SIMPLE_GIL_MANAGEMENT)
13
13
14
- #include < cassert>
14
+ # include " detail/common.h"
15
+ # include " gil_simple.h"
15
16
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"
17
27
# include " detail/internals.h"
18
- #endif
28
+
29
+ # include < cassert>
19
30
20
31
PYBIND11_NAMESPACE_BEGIN (PYBIND11_NAMESPACE)
21
32
@@ -26,8 +37,6 @@ PyThreadState *get_thread_state_unchecked();
26
37
27
38
PYBIND11_NAMESPACE_END (detail)
28
39
29
- #if !defined(PYBIND11_SIMPLE_GIL_MANAGEMENT)
30
-
31
40
/* The functions below essentially reproduce the PyGILState_* API using a RAII
32
41
* pattern, but there are a few important differences:
33
42
*
@@ -182,34 +191,6 @@ class gil_scoped_release {
182
191
bool active = true ;
183
192
};
184
193
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
-
215
194
PYBIND11_NAMESPACE_END (PYBIND11_NAMESPACE)
195
+
196
+ #endif // !PYBIND11_SIMPLE_GIL_MANAGEMENT
0 commit comments