From e728a5bc3db296b4b67c2d3e5b56558c42c566a8 Mon Sep 17 00:00:00 2001 From: Thomas Grill Date: Mon, 21 Jun 2004 14:08:57 +0000 Subject: "" svn path=/trunk/; revision=1826 --- externals/grill/py/source/main.h | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'externals/grill/py/source/main.h') diff --git a/externals/grill/py/source/main.h b/externals/grill/py/source/main.h index d6ca52cb..2e8419d3 100644 --- a/externals/grill/py/source/main.h +++ b/externals/grill/py/source/main.h @@ -50,6 +50,8 @@ WARRANTIES, see the file, "license.txt," in this distribution. #include "main.h" +typedef std::map PyThrMap; + class py: public flext_base { @@ -60,7 +62,7 @@ public: ~py(); static V lib_setup(); - static PyObject *MakePyArgs(const t_symbol *s,const AtomList &args,I inlet = -1,BL withself = false); + static PyObject *MakePyArgs(const t_symbol *s,int argc,const t_atom *argv,I inlet = -1,BL withself = false); static AtomList *GetPyArgs(PyObject *pValue,PyObject **self = NULL); protected: @@ -74,7 +76,6 @@ protected: PyObject *module,*dict; // inherited user class module and associated dictionary - static I pyref; static const C *py_doc; V GetDir(PyObject *obj,AtomList &lst); @@ -83,6 +84,7 @@ protected: V AddToPath(const C *dir); V SetArgs(I argc,const t_atom *argv); V ImportModule(const C *name); + V UnimportModule(); V ReloadModule(); V Register(const C *reg); @@ -124,16 +126,17 @@ protected: V tick(V *); public: - static PyInterpreterState *pystate; #ifdef FLEXT_THREADS - static std::map pythrmap; + static PyInterpreterState *pystate; + static PyThreadState *pythrmain; + static PyThrMap pythrmap; ThrMutex mutex; - V Lock() { mutex.Unlock(); } - V Unlock() { mutex.Unlock(); } + inline V Lock() { mutex.Unlock(); } + inline V Unlock() { mutex.Unlock(); } #else - V Lock() {} - V Unlock() {} + inline V Lock() {} + inline V Unlock() {} #endif static PyObject* StdOut_Write(PyObject* Self, PyObject* Args); @@ -152,11 +155,14 @@ protected: #ifdef FLEXT_THREADS +// if thread is not found in the thread map, the state of the system thread is used +// we have yet to see if this has bad side-effects + #define PY_LOCK \ { \ PyEval_AcquireLock(); \ - PyThreadState *__st = pythrmap[GetThreadId()]; \ - FLEXT_ASSERT(__st != NULL); \ + PyThrMap::iterator it = pythrmap.find(GetThreadId()); \ + PyThreadState *__st = it != pythrmap.end()?it->second:pythrmain; \ PyThreadState *__oldst = PyThreadState_Swap(__st); #define PY_UNLOCK \ -- cgit v1.2.1