${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/..
${PROJECT_BINARY_DIR}/idl
- ${GUI_INCLUDE_DIRS} # For PyLockWrapper
)
SET(COMMON_SOURCES
${OMNIORB_LIBRARIES}
${PYTHON_LIBRARIES}
${MEDCoupling_medcoupling} ${MEDCoupling_medloader} ${MEDCoupling_medcouplingremapper}
- ${GUI_PyInterp}
)
# This undefines the macros MIN and MAX which are specified in the windows headers
//
// Authors: A Bruneton (CEA), C Aguerre (EdF)
+#include "MEDPyLockWrapper.hxx"
#include "MEDFactoryClient.hxx"
#include "MEDPresentation.hxx"
#include "MEDPresentationException.hxx"
#include <SALOME_KernelServices.hxx>
#undef LOG
#include <Basics_Utils.hxx>
-#include <PyInterp_Utils.h>
#include <sstream>
{
STDLOG("~MEDPresentation(): clear display");
{
- PyLockWrapper lock;
+ MEDPyLockWrapper lock;
std::ostringstream oss_o, oss_v, oss;
oss_o << "__obj" << _objId;
oss_v << "__view" << _renderViewPyId;
void
MEDPresentation::execPyLine(const std::string & lin)
{
- PyLockWrapper lock;
+ MEDPyLockWrapper lock;
// STDLOG("@@@@ MEDPresentation::execPyLine() about to exec >> " << lin);
if(PyRun_SimpleString(lin.c_str()))
{
void
MEDPresentation::internalGeneratePipeline()
{
- PyLockWrapper lock;
+ MEDPyLockWrapper lock;
pushAndExecPyLine( "import pvsimple as pvs;");
}
void
MEDPresentation::activateView()
{
- PyLockWrapper lock;
+ MEDPyLockWrapper lock;
std::ostringstream oss;
oss << "pvs.SetActiveView(__view" << _renderViewPyId << ");";
void
MEDPresentation::fillAvailableFieldComponents()
{
- PyLockWrapper lock; // GIL!
+ MEDPyLockWrapper lock; // GIL!
std::ostringstream oss_o;
oss_o << "__obj" << _objId; std::string obj(oss_o.str());
#ifndef SRC_MEDCALC_CMP_MEDPRESENTATION_HXX_
#define SRC_MEDCALC_CMP_MEDPRESENTATION_HXX_
-#include "MEDCouplingRefCountObject.hxx"
#include <Python.h>
+#include "MEDCouplingRefCountObject.hxx"
#include "MEDCALC.hxx"
#include <SALOMEconfig.h>
#ifndef _MED_PRESENTATION_TXX_
#define _MED_PRESENTATION_TXX_
+#include "MEDPyLockWrapper.hxx"
#include <sstream>
#include <SALOME_KernelServices.hxx>
-#include <PyInterp_Utils.h>
template<typename PresentationType, typename PresentationParameters>
void
// Update ParaView pipeline:
{
- PyLockWrapper lock;
+ MEDPyLockWrapper lock;
std::ostringstream oss;
std::string cmd = getComponentSelectionCommand();
// Update the pipeline:
{
- PyLockWrapper lock;
+ MEDPyLockWrapper lock;
std::string cmd = getColorMapCommand();
pushAndExecPyLine(cmd);
pushAndExecPyLine("pvs.Render();");
// Update the pipeline:
{
- PyLockWrapper lock;
+ MEDPyLockWrapper lock;
std::string cmd = getRescaleCommand();
pushAndExecPyLine(cmd);
pushAndExecPyLine("pvs.Render();");
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
+#include "MEDPyLockWrapper.hxx"
+
#include "MEDPresentationScalarMap.hxx"
#include "MEDPresentationException.hxx"
-#include <PyInterp_Utils.h>
#include <SALOME_KernelServices.hxx>
#undef LOG // should be fixed in KERNEL - double definition
#include <Basics_Utils.hxx>
{
MEDPresentation::internalGeneratePipeline();
- PyLockWrapper lock;
+ MEDPyLockWrapper lock;
std::ostringstream oss_o, oss_d,oss_l, oss, oss_v;
oss_o << "__obj" << _objId; std::string obj(oss_o.str());
--- /dev/null
+// Copyright (C) 2011-2016 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library 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 library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef SRC_MEDCALC_CMP_MEDPYLOCKWRAPPER_HXX_
+#define SRC_MEDCALC_CMP_MEDPYLOCKWRAPPER_HXX_
+
+#include <Python.h>
+
+#ifdef _DEBUG_
+ #include <iostream>
+#endif
+
+/**
+ * \class MEDPyLockWrapper
+ * \brief Python GIL wrapper. Copy of GUI's PyLockWrapper.
+ *
+ * Utility class wrapping the Python GIL acquisition. This makes use of the high level
+ * API (PyGILState_Ensure and PyGILState_Release), and is hence compatible with only
+ * one running Python interpreter (no call to Py_NewInterpreter()).
+ * When the class is instanciated the lock is acquired. It is released at destruction time.
+ * Copy construction (and hence assignation) is forbidden.
+ */
+class MEDPyLockWrapper
+{
+public:
+ /**
+ * \brief Constructor. Automatically acquires GIL.
+ */
+ MEDPyLockWrapper()
+ {
+ _gil_state = PyGILState_Ensure();
+ // Save current thread state for later comparison
+ _state = PyGILState_GetThisThreadState();
+ }
+
+ /**
+ * \brief Destructor. Automatically releases GIL.
+ */
+ ~MEDPyLockWrapper()
+ {
+ PyThreadState* _currState = PyGILState_GetThisThreadState();
+#ifdef _DEBUG_
+ if (_currState != _state)
+ {
+ std::cout << "!!!!!!!!! MEDPyLockWrapper inconsistency - now entering infinite loop for debugging\n";
+ while(1);
+ }
+#endif
+ PyGILState_Release(_gil_state);
+ }
+
+private:
+ PyGILState_STATE _gil_state;
+ PyThreadState* _state;
+
+ // "Rule of 3" - Forbid usage of copy operator and copy-constructor
+ MEDPyLockWrapper(const MEDPyLockWrapper & another);
+ const MEDPyLockWrapper & operator=(const MEDPyLockWrapper & another);
+};
+#endif /* SRC_MEDCALC_CMP_MEDPYLOCKWRAPPER_HXX_ */