General KERNEL Documentation     End User KERNEL Services  


src/Container/Container_init_python.hxx

Go to the documentation of this file.
00001 //  SALOME Container : implementation of container and engine for Kernel
00002 //
00003 //  Copyright (C) 2003  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 //
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.3 2006/06/01 11:15:16 jfa Exp $
00028 
00029 #ifndef _CONTAINER_INIT_PYTHON_HXX_
00030 #define _CONTAINER_INIT_PYTHON_HXX_
00031 
00032 #include <pthread.h>  // must be before Python.h !
00033 #include <Python.h>
00034 
00035 
00036 // next two MACRO must be used together only once inside a block
00037 // -------------------------------------------------------------
00038 // protect a sequence of Python calls:
00039 // - Python lock must be acquired for these calls
00040 // - new Python thread state allows multi thread use of the sequence:
00041 //    - Python may release the lock within the sequence, so multiple
00042 //      thread execution of the sequence may occur.
00043 //    - For that case, each sequence call must use a specific Python
00044 //      thread state.
00045 //    - There is no need of C Lock protection of the sequence.
00046 
00047 
00048 #if defined CONTAINER_EXPORTS
00049 #if defined WIN32
00050 #define CONTAINER_EXPORT __declspec( dllexport )
00051 #else
00052 #define CONTAINER_EXPORT
00053 #endif
00054 #else
00055 #if defined WNT
00056 #define CONTAINER_EXPORT __declspec( dllimport )
00057 #else
00058 #define CONTAINER_EXPORT
00059 #endif
00060 #endif
00061 
00062 #define Py_ACQUIRE_NEW_THREAD \
00063   PyEval_AcquireLock(); \
00064   PyThreadState *myTstate = PyThreadState_New(KERNEL_PYTHON::_interp); \
00065   PyThreadState *myoldTstate = PyThreadState_Swap(myTstate);
00066 
00067 #define Py_RELEASE_NEW_THREAD \
00068   PyEval_ReleaseThread(myTstate); \
00069   PyThreadState_Delete(myTstate);
00070 
00071 struct CONTAINER_EXPORT KERNEL_PYTHON
00072 {
00073 #ifdef WNT
00074   static PyThreadState *get_gtstate() { return KERNEL_PYTHON::_gtstate; }
00075   static PyObject *getsalome_shared_modules_module() { return KERNEL_PYTHON::salome_shared_modules_module; }
00076   static PyInterpreterState *get_interp() { return KERNEL_PYTHON::_interp; }
00077 #endif
00078   static PyThreadState *_gtstate;
00079   static PyObject *salome_shared_modules_module;
00080   static PyInterpreterState *_interp;
00081 
00082   static void init_python(int argc, char **argv);
00083 
00084 };
00085 
00086 #endif