aboutsummaryrefslogtreecommitdiffstats
path: root/libshiboken/gilstate.h
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2010-01-15 21:13:48 -0300
committerMarcelo Lira <marcelo.lira@openbossa.org>2010-01-18 14:44:17 -0300
commit79774d9827ba3883ac1862aee86c890634fa21a9 (patch)
tree15b7ddb70cf5dd1c9885b802ac49274bde2aeee1 /libshiboken/gilstate.h
parentd9c5531a3cf0967e2595cef18c63892c0d64d551 (diff)
Adds convenience GilState class to libshiboken.
GilState class puts some sugar over the Python GIL usage and also adds the safety of a final GIL release when the GilState destructor is called when get out of scope.
Diffstat (limited to 'libshiboken/gilstate.h')
-rw-r--r--libshiboken/gilstate.h55
1 files changed, 55 insertions, 0 deletions
diff --git a/libshiboken/gilstate.h b/libshiboken/gilstate.h
new file mode 100644
index 000000000..ee3808ade
--- /dev/null
+++ b/libshiboken/gilstate.h
@@ -0,0 +1,55 @@
+/*
+ * This file is part of the Shiboken Python Bindings Generator project.
+ *
+ * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+ *
+ * Contact: PySide team <contact@pyside.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation. Please
+ * review the following information to ensure the GNU Lesser General
+ * Public License version 2.1 requirements will be met:
+ * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+ *
+ * As a special exception to the GNU Lesser General Public License
+ * version 2.1, the object code form of a "work that uses the Library"
+ * may incorporate material from a header file that is part of the
+ * Library. You may distribute such object code under terms of your
+ * choice, provided that the incorporated material (i) does not exceed
+ * more than 5% of the total size of the Library; and (ii) is limited to
+ * numerical parameters, data structure layouts, accessors, macros,
+ * inline functions and templates.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#ifndef GILSTATE_H
+#define GILSTATE_H
+
+#include <Python.h>
+
+namespace Shiboken
+{
+
+class LIBSHIBOKEN_API GilState
+{
+public:
+ GilState() { m_gstate = PyGILState_Ensure(); }
+ ~GilState() { PyGILState_Release(m_gstate); }
+private:
+ PyGILState_STATE m_gstate;
+};
+
+} // namespace Shiboken
+
+#endif // GILSTATE_H
+