diff options
author | Josh Blum | 2012-11-08 00:10:26 -0800 |
---|---|---|
committer | Josh Blum | 2012-11-08 00:10:26 -0800 |
commit | d1d9b98d31d17b9c7b8b80105de890c287ccf96e (patch) | |
tree | 26944b48f8eb758fe5ecaaa41a5bcb9e7db6d495 /python/gras/GRAS_HierBlock.i | |
parent | 4e6548ed237f3d6eda4383d6a07a4d1e99f404f6 (diff) | |
download | sandhi-d1d9b98d31d17b9c7b8b80105de890c287ccf96e.tar.gz sandhi-d1d9b98d31d17b9c7b8b80105de890c287ccf96e.tar.bz2 sandhi-d1d9b98d31d17b9c7b8b80105de890c287ccf96e.zip |
lot of python locking hell...
Diffstat (limited to 'python/gras/GRAS_HierBlock.i')
-rw-r--r-- | python/gras/GRAS_HierBlock.i | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/python/gras/GRAS_HierBlock.i b/python/gras/GRAS_HierBlock.i index 16142e5..c84dc0e 100644 --- a/python/gras/GRAS_HierBlock.i +++ b/python/gras/GRAS_HierBlock.i @@ -33,6 +33,27 @@ } } +//////////////////////////////////////////////////////////////////////// +// 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; +}; + +%} + %{ #include <gras/hier_block.hpp> #include <gras/top_block.hpp> @@ -64,19 +85,28 @@ struct TopBlockPython : TopBlock //NOP } + void start(void) + { + PyTSPhondler phil; + TopBlock::start(); + } + + void stop(void) + { + PyTSPhondler phil; + TopBlock::stop(); + } + void wait(void) { - PyThreadState *s = PyEval_SaveThread(); + PyTSPhondler phil; TopBlock::wait(); - PyEval_RestoreThread(s); } bool wait(const double timeout) { - PyThreadState *s = PyEval_SaveThread(); - const bool ret = TopBlock::wait(timeout); - PyEval_RestoreThread(s); - return ret; + PyTSPhondler phil; + return TopBlock::wait(timeout); } }; |