31 | | class XapianSWIG_Python_Thread_Block { |
32 | | bool status; |
33 | | PyGILState_STATE state; |
34 | | public: |
35 | | void end() { if (status) { PyGILState_Release(state); status = false;} } |
36 | | XapianSWIG_Python_Thread_Block() : status(PyEval_ThreadsInitialized()) { if (status) state = PyGILState_Ensure(); } |
37 | | ~XapianSWIG_Python_Thread_Block() { end(); } |
38 | | }; |
39 | | class XapianSWIG_Python_Thread_Allow { |
40 | | bool status; |
41 | | PyThreadState *save; |
42 | | public: |
43 | | void end() { if (status) { PyEval_RestoreThread(save); status = false; }} |
44 | | XapianSWIG_Python_Thread_Allow() : status(PyEval_ThreadsInitialized()) { if (status) save = PyEval_SaveThread(); } |
45 | | ~XapianSWIG_Python_Thread_Allow() { end(); } |
46 | | }; |
| 31 | static __thread PyThreadState * swig_pythreadstate = NULL; |
| 32 | |
| 33 | class XapianSWIG_Python_Thread_Block { |
| 34 | bool status; |
| 35 | public: |
| 36 | XapianSWIG_Python_Thread_Block() |
| 37 | : status(PyEval_ThreadsInitialized() && swig_pythreadstate) { |
| 38 | if (status) { |
| 39 | PyEval_RestoreThread(swig_pythreadstate); |
| 40 | swig_pythreadstate = NULL; |
| 41 | } |
| 42 | } |
| 43 | void end() { |
| 44 | if (status) { |
| 45 | if (swig_pythreadstate) Py_FatalError("swig_pythreadstate set in XapianSWIG_Python_Thread_Block::end()"); |
| 46 | swig_pythreadstate = PyEval_SaveThread(); |
| 47 | status = false; |
| 48 | } |
| 49 | } |
| 50 | ~XapianSWIG_Python_Thread_Block() { end(); } |
| 51 | }; |
| 52 | |
| 53 | class XapianSWIG_Python_Thread_Allow { |
| 54 | bool status; |
| 55 | public: |
| 56 | XapianSWIG_Python_Thread_Allow() : status(PyEval_ThreadsInitialized()) { |
| 57 | if (status) { |
| 58 | if (swig_pythreadstate) Py_FatalError("swig_pythreadstate set in XapianSWIG_Python_Thread_Allow ctor"); |
| 59 | swig_pythreadstate = PyEval_SaveThread(); |
| 60 | } |
| 61 | } |
| 62 | void end() { |
| 63 | if (status) { |
| 64 | if (!swig_pythreadstate) Py_FatalError("swig_pythreadstate unset in XapianSWIG_Python_Thread_Block::end()"); |
| 65 | PyEval_RestoreThread(swig_pythreadstate); |
| 66 | swig_pythreadstate = NULL; |
| 67 | status = false; |
| 68 | } |
| 69 | } |
| 70 | ~XapianSWIG_Python_Thread_Allow() { end(); } |
| 71 | }; |