00001 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE 00002 // 00003 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, 00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 00005 // 00006 // This library is free software; you can redistribute it and/or 00007 // modify it under the terms of the GNU Lesser General Public 00008 // License as published by the Free Software Foundation; either 00009 // version 2.1 of the License. 00010 // 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 // Lesser General Public License for more details. 00015 // 00016 // You should have received a copy of the GNU Lesser General Public 00017 // License along with this library; if not, write to the Free Software 00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 // 00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com 00021 // 00022 // SALOME Container : implementation of container and engine for Kernel 00023 // File : Container_init_python.hxx 00024 // Author : Paul RASCLE, EDF 00025 // Module : KERNEL 00026 // $Header$ 00027 // 00028 #ifndef _CONTAINER_INIT_PYTHON_HXX_ 00029 #define _CONTAINER_INIT_PYTHON_HXX_ 00030 00031 #include "SALOME_Container.hxx" 00032 #include <SALOMEconfig.h> 00033 00034 #include <pthread.h> // must be before Python.h ! 00035 #include <Python.h> 00036 00037 00038 // next two MACRO must be used together only once inside a block 00039 // ------------------------------------------------------------- 00040 // protect a sequence of Python calls: 00041 // - Python lock must be acquired for these calls 00042 // - new Python thread state allows multi thread use of the sequence: 00043 // - Python may release the lock within the sequence, so multiple 00044 // thread execution of the sequence may occur. 00045 // - For that case, each sequence call must use a specific Python 00046 // thread state. 00047 // - There is no need of C Lock protection of the sequence. 00048 00049 00050 #define Py_ACQUIRE_NEW_THREAD \ 00051 PyEval_AcquireLock(); \ 00052 PyThreadState *myTstate = PyThreadState_New(KERNEL_PYTHON::_interp); \ 00053 PyThreadState_Swap(myTstate); 00054 00055 #define Py_RELEASE_NEW_THREAD \ 00056 PyEval_ReleaseThread(myTstate); \ 00057 PyThreadState_Delete(myTstate); 00058 00059 struct CONTAINER_EXPORT KERNEL_PYTHON 00060 { 00061 #ifdef WIN32 00062 static PyThreadState *get_gtstate() { return KERNEL_PYTHON::_gtstate; } 00063 static PyObject *getsalome_shared_modules_module() { return KERNEL_PYTHON::salome_shared_modules_module; } 00064 static PyInterpreterState *get_interp() { return KERNEL_PYTHON::_interp; } 00065 #endif 00066 static PyThreadState *_gtstate; 00067 static PyObject *salome_shared_modules_module; 00068 static PyInterpreterState *_interp; 00069 00070 static void init_python(int argc, char **argv); 00071 00072 }; 00073 00074 #endif