using RAII to manage GIL -- still fails to handle exceptions correctly
This commit is contained in:
parent
58174f6ada
commit
0e27c772aa
@ -105,6 +105,22 @@ static inline int* refcountFromPyObject(const PyObject* obj)
|
|||||||
return (int*)((size_t)obj + REFCOUNT_OFFSET);
|
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
|
class NumpyAllocator : public MatAllocator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -19,9 +19,10 @@ gen_template_parse_args = Template("""const char* keywords[] = { $kw_list, NULL
|
|||||||
gen_template_func_body = Template("""$code_decl
|
gen_template_func_body = Template("""$code_decl
|
||||||
$code_parse
|
$code_parse
|
||||||
{
|
{
|
||||||
Py_BEGIN_ALLOW_THREADS
|
{
|
||||||
$code_fcall;
|
PyAllowThreads allow;
|
||||||
Py_END_ALLOW_THREADS
|
$code_fcall;
|
||||||
|
}
|
||||||
$code_ret;
|
$code_ret;
|
||||||
}
|
}
|
||||||
""")
|
""")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user