1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
class GILHelper {
public:
GILHelper() {
state = PyGILState_Ensure();
}
~GILHelper() {
PyGILState_Release(state);
}
private:
PyGILState_STATE state;
};
class CFloat32CustomPython : public astra::CFloat32CustomMemory {
public:
CFloat32CustomPython(PyArrayObject * arrIn)
{
GILHelper gil; // hold GIL during this function
arr = arrIn;
// Set pointer to numpy data pointer
m_fPtr = (float *)PyArray_DATA(arr);
// Increase reference count since ASTRA has a reference
Py_INCREF(arr);
}
virtual ~CFloat32CustomPython() {
GILHelper gil; // hold GIL during this function
// Decrease reference count since ASTRA object is destroyed
Py_DECREF(arr);
}
private:
PyArrayObject* arr;
};
|