using RAII to manage GIL -- still fails to handle exceptions correctly

This commit is contained in:
Alexander Mordvintsev
2012-03-07 12:46:21 +00:00
parent 58174f6ada
commit 0e27c772aa
2 changed files with 20 additions and 3 deletions

View File

@@ -105,6 +105,22 @@ static inline int* refcountFromPyObject(const PyObject* obj)
return (int*)((size_t)obj + REFCOUNT_OFFSET);
}
class PyAllowThreads
{
public:
PyAllowThreads() : _state(PyEval_SaveThread())
{
//printf("+GIL\n");
}
~PyAllowThreads()
{
PyEval_RestoreThread(_state);
//printf("-GIL\n");
}
private:
PyThreadState* _state;
};
class NumpyAllocator : public MatAllocator
{
public: