From 687db5a645e4a32f47b7bc0479950c50aaca6632 Mon Sep 17 00:00:00 2001 From: Renato Filho Date: Tue, 24 Aug 2010 16:40:00 -0300 Subject: Move ThreadStateSaver implementation from the header to a cpp file. Reviewer: Luciano Wolf Hugo Parente Lima --- libshiboken/CMakeLists.txt | 3 +- libshiboken/threadstatesaver.cpp | 64 ++++++++++++++++++++++++++++++++++++++++ libshiboken/threadstatesaver.h | 17 ++++------- 3 files changed, 72 insertions(+), 12 deletions(-) create mode 100644 libshiboken/threadstatesaver.cpp diff --git a/libshiboken/CMakeLists.txt b/libshiboken/CMakeLists.txt index 74d0c0219..ecdd4aafc 100644 --- a/libshiboken/CMakeLists.txt +++ b/libshiboken/CMakeLists.txt @@ -1,5 +1,4 @@ project(libshiboken) - #Find installed sparsehash find_path(SPARSEHASH_INCLUDE_PATH sparseconfig.h PATH_SUFFIXES "/google/sparsehash") if(SPARSEHASH_INCLUDE_PATH) @@ -8,6 +7,7 @@ else() set(SPARSEHASH_INCLUDE_PATH ${CMAKE_SOURCE_DIR}/ext/sparsehash) endif() +add_definitions(-DWITH_THREAD) set(libshiboken_MAJOR_VERSION ${shiboken_MAJOR_VERSION}) set(libshiboken_MINOR_VERSION ${shiboken_MINOR_VERSION}) set(libshiboken_MICRO_VERSION ${shiboken_MICRO_VERSION}) @@ -26,6 +26,7 @@ basewrapper.cpp helper.cpp pyenum.cpp bindingmanager.cpp +threadstatesaver.cpp typeresolver.cpp ) diff --git a/libshiboken/threadstatesaver.cpp b/libshiboken/threadstatesaver.cpp new file mode 100644 index 000000000..c3ffd20ee --- /dev/null +++ b/libshiboken/threadstatesaver.cpp @@ -0,0 +1,64 @@ +/* + * This file is part of the Shiboken Python Bindings Generator project. + * + * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). + * + * Contact: PySide team + * + * 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 + */ + +#include "threadstatesaver.h" + +namespace Shiboken +{ + +ThreadStateSaver::ThreadStateSaver() + : m_threadState(0) + {} + +ThreadStateSaver::~ThreadStateSaver() +{ + restore(); +} + +void ThreadStateSaver::save() +{ + if (PyEval_ThreadsInitialized()) + m_threadState = PyEval_SaveThread(); +} + +void ThreadStateSaver::restore() +{ + if (m_threadState) { + PyEval_RestoreThread(m_threadState); + m_threadState = 0; + } +} + +} // namespace Shiboken + diff --git a/libshiboken/threadstatesaver.h b/libshiboken/threadstatesaver.h index 47f05f82e..3629f913e 100644 --- a/libshiboken/threadstatesaver.h +++ b/libshiboken/threadstatesaver.h @@ -36,23 +36,18 @@ #define THREADSTATESAVER_H #include +#include namespace Shiboken { -class ThreadStateSaver +class LIBSHIBOKEN_API ThreadStateSaver { public: - ThreadStateSaver() : m_threadState(0) {} - ~ThreadStateSaver() { restore(); } - inline void save() { m_threadState = PyEval_SaveThread(); } - inline void restore() - { - if (m_threadState) { - PyEval_RestoreThread(m_threadState); - m_threadState = 0; - } - } + ThreadStateSaver(); + ~ThreadStateSaver(); + void save(); + void restore(); private: PyThreadState* m_threadState; }; -- cgit v1.2.3