diff --git a/bindings/python/src/gil.hpp b/bindings/python/src/gil.hpp index 6dd1dc688..e2da53840 100644 --- a/bindings/python/src/gil.hpp +++ b/bindings/python/src/gil.hpp @@ -19,90 +19,35 @@ // RAII helper to release GIL. struct allow_threading_guard { - allow_threading_guard() - : save(PyEval_SaveThread()) - {} - - ~allow_threading_guard() - { - PyEval_RestoreThread(save); - } - + allow_threading_guard() : save(PyEval_SaveThread()) {} + ~allow_threading_guard() { PyEval_RestoreThread(save); } PyThreadState* save; }; struct lock_gil { - lock_gil() - : state(PyGILState_Ensure()) - {} - - ~lock_gil() - { - PyGILState_Release(state); - } - + lock_gil() : state(PyGILState_Ensure()) {} + ~lock_gil() { PyGILState_Release(state); } PyGILState_STATE state; }; template struct allow_threading { - allow_threading(F fn) - : fn(fn) - {} - - template - R operator()(A0& a0) + allow_threading(F fn) : fn(fn) {} + template + R operator()(Self&& s, Args&&... args) { allow_threading_guard guard; - return (a0.*fn)(); + return (std::forward(s).*fn)(std::forward(args)...); } - - template - R operator()(A0& a0, A1& a1) - { - allow_threading_guard guard; - return (a0.*fn)(a1); - } - - template - R operator()(A0& a0, A1& a1, A2& a2) - { - allow_threading_guard guard; - return (a0.*fn)(a1,a2); - } - - template - R operator()(A0& a0, A1& a1, A2& a2, A3& a3) - { - allow_threading_guard guard; - return (a0.*fn)(a1,a2,a3); - } - - template - R operator()(A0& a0, A1& a1, A2& a2, A3& a3, A4& a4) - { - allow_threading_guard guard; - return (a0.*fn)(a1,a2,a3,a4); - } - - template - R operator()(A0& a0, A1& a1, A2& a2, A3& a3, A4& a4, A5& a5) - { - allow_threading_guard guard; - return (a0.*fn)(a1,a2,a3,a4,a5); - } - F fn; }; template struct visitor : boost::python::def_visitor> { - visitor(F fn) - : fn(fn) - {} + visitor(F fn) : fn(fn) {} template void visit_aux(