knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
gil.h
Go to the documentation of this file.
1 /*
2  * This file is part of KnowRob, please consult
3  * https://github.com/knowrob/knowrob for license details.
4  */
5 
6 #ifndef KNOWROB_PY_GIL_H
7 #define KNOWROB_PY_GIL_H
8 
9 #include <boost/python.hpp>
10 
11 namespace knowrob::py {
17  struct no_gil {
18  public:
19  no_gil() { state_ = PyEval_SaveThread(); }
20 
21  ~no_gil() { PyEval_RestoreThread(state_); }
22 
23  private:
24  PyThreadState *state_;
25  };
26 
31  class gil_lock {
32  public:
33  gil_lock() { state_ = PyGILState_Ensure(); }
34 
35  ~gil_lock() { PyGILState_Release(state_); }
36 
37  private:
38  PyGILState_STATE state_;
39  };
40 }
41 
42 #endif //KNOWROB_PY_GIL_H