aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6/libshiboken/gilstate.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'sources/shiboken6/libshiboken/gilstate.cpp')
-rw-r--r--sources/shiboken6/libshiboken/gilstate.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/sources/shiboken6/libshiboken/gilstate.cpp b/sources/shiboken6/libshiboken/gilstate.cpp
new file mode 100644
index 000000000..8daa93b8b
--- /dev/null
+++ b/sources/shiboken6/libshiboken/gilstate.cpp
@@ -0,0 +1,38 @@
+// 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 "gilstate.h"
+
+namespace Shiboken
+{
+
+GilState::GilState()
+{
+ if (Py_IsInitialized()) {
+ m_gstate = PyGILState_Ensure();
+ m_locked = true;
+ }
+}
+
+GilState::~GilState()
+{
+ release();
+}
+
+void GilState::release()
+{
+ if (m_locked && Py_IsInitialized()) {
+ PyGILState_Release(m_gstate);
+ m_locked = false;
+ }
+}
+
+// Abandon the lock: Only for special situations, like termination of a
+// POSIX thread (PYSIDE 1282).
+void GilState::abandon()
+{
+ m_locked = false;
+}
+
+} // namespace Shiboken
+