diff options
Diffstat (limited to 'python/gras/GRAS_Utils.i')
-rw-r--r-- | python/gras/GRAS_Utils.i | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/python/gras/GRAS_Utils.i b/python/gras/GRAS_Utils.i new file mode 100644 index 0000000..afe3314 --- /dev/null +++ b/python/gras/GRAS_Utils.i @@ -0,0 +1,43 @@ +// Copyright (C) by Josh Blum. See LICENSE.txt for licensing information. + +//////////////////////////////////////////////////////////////////////// +// Simple class to deal with smart locking/unlocking of python GIL +//////////////////////////////////////////////////////////////////////// +%{ + +struct PyGILPhondler +{ + PyGILPhondler(void): + s(PyGILState_Ensure()) + { + //NOP + } + ~PyGILPhondler(void) + { + PyGILState_Release(s); + } + PyGILState_STATE s; +}; + +%} + +//////////////////////////////////////////////////////////////////////// +// Simple class to deal with smart save/restore of python thread state +//////////////////////////////////////////////////////////////////////// +%{ + +struct PyTSPhondler +{ + PyTSPhondler(void): + s(PyEval_SaveThread()) + { + //NOP + } + ~PyTSPhondler(void) + { + PyEval_RestoreThread(s); + } + PyThreadState *s; +}; + +%} |