aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6/libshiboken/threadstatesaver.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'sources/shiboken6/libshiboken/threadstatesaver.cpp')
-rw-r--r--sources/shiboken6/libshiboken/threadstatesaver.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/sources/shiboken6/libshiboken/threadstatesaver.cpp b/sources/shiboken6/libshiboken/threadstatesaver.cpp
new file mode 100644
index 000000000..9f74ed442
--- /dev/null
+++ b/sources/shiboken6/libshiboken/threadstatesaver.cpp
@@ -0,0 +1,31 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "threadstatesaver.h"
+
+namespace Shiboken
+{
+
+ThreadStateSaver::ThreadStateSaver() = default;
+
+ThreadStateSaver::~ThreadStateSaver()
+{
+ restore();
+}
+
+void ThreadStateSaver::save()
+{
+ if (Py_IsInitialized())
+ m_threadState = PyEval_SaveThread();
+}
+
+void ThreadStateSaver::restore()
+{
+ if (m_threadState) {
+ PyEval_RestoreThread(m_threadState);
+ m_threadState = nullptr;
+ }
+}
+
+} // namespace Shiboken
+