Skip to content
Snippets Groups Projects
Commit c4008b8a authored by Matthew Andrew's avatar Matthew Andrew
Browse files

Split into header and source file Re #23266

parent ccde3a58
No related branches found
No related tags found
No related merge requests found
......@@ -29,22 +29,6 @@ private:
PyThreadState *m_saved;
};
ReleaseGlobalInterpreterLock::ReleaseGlobalInterpreterLock()
: m_tracefunc(nullptr), m_tracearg(nullptr), m_saved(nullptr) {
PyThreadState *curThreadState = PyThreadState_GET();
m_tracefunc = curThreadState->c_tracefunc;
m_tracearg = curThreadState->c_traceobj;
Py_XINCREF(m_tracearg);
PyEval_SetTrace(nullptr, nullptr);
m_saved = PyEval_SaveThread();
}
ReleaseGlobalInterpreterLock::~ReleaseGlobalInterpreterLock() {
PyEval_RestoreThread(m_saved);
PyEval_SetTrace(m_tracefunc, m_tracearg);
Py_XDECREF(m_tracearg);
}
} // namespace Environment
} // namespace PythonInterface
} // namespace Mantid
......
......@@ -89,6 +89,7 @@ set ( SRC_FILES
src/Registry/TypeRegistry.cpp
src/Environment/ErrorHandling.cpp
src/Environment/GlobalInterpreterLock.cpp
src/Environment/ReleaseGlobalInterpreterLock.cpp
src/Environment/WrapperHelpers.cpp
)
......
#include "MantidPythonInterface/kernel/Environment/ReleaseGlobalInterpreterLock.h"
namespace Mantid {
namespace PythonInterface {
namespace Environment {
/**
* Ensures this thread releases the Python GIL also save trace information
* to be restored upon destruction.
*/
ReleaseGlobalInterpreterLock::ReleaseGlobalInterpreterLock()
: m_tracefunc(nullptr), m_tracearg(nullptr), m_saved(nullptr) {
PyThreadState *curThreadState = PyThreadState_GET();
m_tracefunc = curThreadState->c_tracefunc;
m_tracearg = curThreadState->c_traceobj;
Py_XINCREF(m_tracearg);
PyEval_SetTrace(nullptr, nullptr);
m_saved = PyEval_SaveThread();
}
/**
* Restores the Python GIL to the thread when the object falls out of scope.
*/
ReleaseGlobalInterpreterLock::~ReleaseGlobalInterpreterLock() {
PyEval_RestoreThread(m_saved);
PyEval_SetTrace(m_tracefunc, m_tracearg);
Py_XDECREF(m_tracearg);
}
} // namespace Environment
} // namespace PythonInterface
} // namespace Mantid
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment