14 #if defined(WITH_THREAD) && !defined(PYBIND11_SIMPLE_GIL_MANAGEMENT)
27 #if defined(WITH_THREAD)
29 # if !defined(PYBIND11_SIMPLE_GIL_MANAGEMENT)
65 tstate = PyGILState_GetThisThreadState();
69 tstate = PyThreadState_New(
internals.istate);
70 # if defined(PYBIND11_DETAILED_ERROR_MESSAGES)
72 pybind11_fail(
"scoped_acquire: could not create thread state!");
75 tstate->gilstate_counter = 0;
82 PyEval_AcquireThread(tstate);
91 void inc_ref() { ++tstate->gilstate_counter; }
94 --tstate->gilstate_counter;
95 # if defined(PYBIND11_DETAILED_ERROR_MESSAGES)
97 pybind11_fail(
"scoped_acquire::dec_ref(): thread state must be current!");
99 if (tstate->gilstate_counter < 0) {
100 pybind11_fail(
"scoped_acquire::dec_ref(): reference count underflow!");
103 if (tstate->gilstate_counter == 0) {
104 # if defined(PYBIND11_DETAILED_ERROR_MESSAGES)
109 PyThreadState_Clear(tstate);
111 PyThreadState_DeleteCurrent();
133 PyThreadState *tstate =
nullptr;
146 tstate = PyEval_SaveThread();
171 PyEval_RestoreThread(tstate);
182 PyThreadState *tstate;
187 # else // PYBIND11_SIMPLE_GIL_MANAGEMENT
190 PyGILState_STATE
state;
201 PyThreadState *
state;
211 # endif // PYBIND11_SIMPLE_GIL_MANAGEMENT
219 (void) (
this != (
this + 1));
230 (void) (
this != (
this + 1));
237 #endif // WITH_THREAD