From c4008b8aaef23c81aed421421e6139f65b36995a Mon Sep 17 00:00:00 2001
From: Matthew Andrew <matthew.andrew@stfc.ac.uk>
Date: Wed, 15 Aug 2018 17:20:50 +0100
Subject: [PATCH] Split into header and source file Re #23266

---
 .../ReleaseGlobalInterpreterLock.h            | 16 ----------
 .../mantid/kernel/CMakeLists.txt              |  1 +
 .../ReleaseGlobalInterpreterLock.cpp          | 32 +++++++++++++++++++
 3 files changed, 33 insertions(+), 16 deletions(-)
 create mode 100644 Framework/PythonInterface/mantid/kernel/src/Environment/ReleaseGlobalInterpreterLock.cpp

diff --git a/Framework/PythonInterface/inc/MantidPythonInterface/kernel/Environment/ReleaseGlobalInterpreterLock.h b/Framework/PythonInterface/inc/MantidPythonInterface/kernel/Environment/ReleaseGlobalInterpreterLock.h
index 8003167db39..c1f45931c66 100644
--- a/Framework/PythonInterface/inc/MantidPythonInterface/kernel/Environment/ReleaseGlobalInterpreterLock.h
+++ b/Framework/PythonInterface/inc/MantidPythonInterface/kernel/Environment/ReleaseGlobalInterpreterLock.h
@@ -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
diff --git a/Framework/PythonInterface/mantid/kernel/CMakeLists.txt b/Framework/PythonInterface/mantid/kernel/CMakeLists.txt
index ca639abb8e9..f78be07e854 100644
--- a/Framework/PythonInterface/mantid/kernel/CMakeLists.txt
+++ b/Framework/PythonInterface/mantid/kernel/CMakeLists.txt
@@ -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
 )
 
diff --git a/Framework/PythonInterface/mantid/kernel/src/Environment/ReleaseGlobalInterpreterLock.cpp b/Framework/PythonInterface/mantid/kernel/src/Environment/ReleaseGlobalInterpreterLock.cpp
new file mode 100644
index 00000000000..89d8b4c56a0
--- /dev/null
+++ b/Framework/PythonInterface/mantid/kernel/src/Environment/ReleaseGlobalInterpreterLock.cpp
@@ -0,0 +1,32 @@
+#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
-- 
GitLab