HAMR
The Heterogeneous Accelerator Memory Resource
hamr_gil_state.h
1 #ifndef hamr_gil_state_h
2 #define hamr_gil_state_h
3 
4 #include <Python.h>
5 
6 namespace hamr
7 {
8 
9 /// A RAII helper for managing the Python GIL.
10 /** The GIL is aquired and held while the object exists. The GIL must be held
11  * by C++ code invoking any Python C-API calls.
12  */
13 class HAMR_EXPORT gil_state
14 {
15 public:
16  gil_state()
17  { m_state = PyGILState_Ensure(); }
18 
19  ~gil_state()
20  { PyGILState_Release(m_state); }
21 
22  gil_state(const gil_state&) = delete;
23  void operator=(const gil_state&) = delete;
24 
25 private:
26  PyGILState_STATE m_state;
27 };
28 
29 }
30 
31 #endif
hamr::gil_state
A RAII helper for managing the Python GIL.
Definition: hamr_gil_state.h:13
hamr
heterogeneous accelerator memory resource
Definition: hamr_buffer.h:13