Home | History | Annotate | Download | only in python
      1 #if defined(SWIG_PYTHON_NO_THREADS)
      2 #  if defined(SWIG_PYTHON_THREADS)
      3 #    undef SWIG_PYTHON_THREADS
      4 #  endif
      5 #endif
      6 #if defined(SWIG_PYTHON_THREADS) /* Threading support is enabled */
      7 #  if !defined(SWIG_PYTHON_USE_GIL) && !defined(SWIG_PYTHON_NO_USE_GIL)
      8 #    if (PY_VERSION_HEX >= 0x02030000) /* For 2.3 or later, use the PyGILState calls */
      9 #      define SWIG_PYTHON_USE_GIL
     10 #    endif
     11 #  endif
     12 #  if defined(SWIG_PYTHON_USE_GIL) /* Use PyGILState threads calls */
     13 #    ifndef SWIG_PYTHON_INITIALIZE_THREADS
     14 #     define SWIG_PYTHON_INITIALIZE_THREADS  PyEval_InitThreads() 
     15 #    endif
     16 #    ifdef __cplusplus /* C++ code */
     17        class SWIG_Python_Thread_Block {
     18          bool status;
     19          PyGILState_STATE state;
     20        public:
     21          void end() { if (status) { PyGILState_Release(state); status = false;} }
     22          SWIG_Python_Thread_Block() : status(true), state(PyGILState_Ensure()) {}
     23          ~SWIG_Python_Thread_Block() { end(); }
     24        };
     25        class SWIG_Python_Thread_Allow {
     26          bool status;
     27          PyThreadState *save;
     28        public:
     29          void end() { if (status) { PyEval_RestoreThread(save); status = false; }}
     30          SWIG_Python_Thread_Allow() : status(true), save(PyEval_SaveThread()) {}
     31          ~SWIG_Python_Thread_Allow() { end(); }
     32        };
     33 #      define SWIG_PYTHON_THREAD_BEGIN_BLOCK   SWIG_Python_Thread_Block _swig_thread_block
     34 #      define SWIG_PYTHON_THREAD_END_BLOCK     _swig_thread_block.end()
     35 #      define SWIG_PYTHON_THREAD_BEGIN_ALLOW   SWIG_Python_Thread_Allow _swig_thread_allow
     36 #      define SWIG_PYTHON_THREAD_END_ALLOW     _swig_thread_allow.end()
     37 #    else /* C code */
     38 #      define SWIG_PYTHON_THREAD_BEGIN_BLOCK   PyGILState_STATE _swig_thread_block = PyGILState_Ensure()
     39 #      define SWIG_PYTHON_THREAD_END_BLOCK     PyGILState_Release(_swig_thread_block)
     40 #      define SWIG_PYTHON_THREAD_BEGIN_ALLOW   PyThreadState *_swig_thread_allow = PyEval_SaveThread()
     41 #      define SWIG_PYTHON_THREAD_END_ALLOW     PyEval_RestoreThread(_swig_thread_allow)
     42 #    endif
     43 #  else /* Old thread way, not implemented, user must provide it */
     44 #    if !defined(SWIG_PYTHON_INITIALIZE_THREADS)
     45 #      define SWIG_PYTHON_INITIALIZE_THREADS
     46 #    endif
     47 #    if !defined(SWIG_PYTHON_THREAD_BEGIN_BLOCK)
     48 #      define SWIG_PYTHON_THREAD_BEGIN_BLOCK
     49 #    endif
     50 #    if !defined(SWIG_PYTHON_THREAD_END_BLOCK)
     51 #      define SWIG_PYTHON_THREAD_END_BLOCK
     52 #    endif
     53 #    if !defined(SWIG_PYTHON_THREAD_BEGIN_ALLOW)
     54 #      define SWIG_PYTHON_THREAD_BEGIN_ALLOW
     55 #    endif
     56 #    if !defined(SWIG_PYTHON_THREAD_END_ALLOW)
     57 #      define SWIG_PYTHON_THREAD_END_ALLOW
     58 #    endif
     59 #  endif
     60 #else /* No thread support */
     61 #  define SWIG_PYTHON_INITIALIZE_THREADS
     62 #  define SWIG_PYTHON_THREAD_BEGIN_BLOCK
     63 #  define SWIG_PYTHON_THREAD_END_BLOCK
     64 #  define SWIG_PYTHON_THREAD_BEGIN_ALLOW
     65 #  define SWIG_PYTHON_THREAD_END_ALLOW
     66 #endif
     67