00001 // Copyright (C) 2007-2011 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 00023 // SALOME Container : implementation of container and engine for Kernel 00024 // File : Container_init_python.hxx 00025 // Author : Paul RASCLE, EDF 00026 // Module : KERNEL 00027 // $Header: /home/server/cvs/KERNEL/KERNEL_SRC/src/Container/Container_init_python.hxx,v 1.5.32.1.6.1 2011-06-01 13:51:39 vsr Exp $ 00028 // 00029 #ifndef _CONTAINER_INIT_PYTHON_HXX_ 00030 #define _CONTAINER_INIT_PYTHON_HXX_ 00031 00032 #include "SALOME_Container.hxx" 00033 #include <SALOMEconfig.h> 00034 00035 #include <pthread.h> // must be before Python.h ! 00036 #include <Python.h> 00037 00038 00039 // next two MACRO must be used together only once inside a block 00040 // ------------------------------------------------------------- 00041 // protect a sequence of Python calls: 00042 // - Python lock must be acquired for these calls 00043 // - new Python thread state allows multi thread use of the sequence: 00044 // - Python may release the lock within the sequence, so multiple 00045 // thread execution of the sequence may occur. 00046 // - For that case, each sequence call must use a specific Python 00047 // thread state. 00048 // - There is no need of C Lock protection of the sequence. 00049 00050 00051 #define Py_ACQUIRE_NEW_THREAD \ 00052 PyEval_AcquireLock(); \ 00053 PyThreadState *myTstate = PyThreadState_New(KERNEL_PYTHON::_interp); \ 00054 PyThreadState_Swap(myTstate); 00055 00056 #define Py_RELEASE_NEW_THREAD \ 00057 PyEval_ReleaseThread(myTstate); \ 00058 PyThreadState_Delete(myTstate); 00059 00060 struct CONTAINER_EXPORT KERNEL_PYTHON 00061 { 00062 #ifdef WIN32 00063 static PyThreadState *get_gtstate() { return KERNEL_PYTHON::_gtstate; } 00064 static PyObject *getsalome_shared_modules_module() { return KERNEL_PYTHON::salome_shared_modules_module; } 00065 static PyInterpreterState *get_interp() { return KERNEL_PYTHON::_interp; } 00066 #endif 00067 static PyThreadState *_gtstate; 00068 static PyObject *salome_shared_modules_module; 00069 static PyInterpreterState *_interp; 00070 00071 static void init_python(int argc, char **argv); 00072 00073 }; 00074 00075 #endif