aboutsummaryrefslogtreecommitdiff
path: root/externals/grill/py/source/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'externals/grill/py/source/main.cpp')
-rw-r--r--externals/grill/py/source/main.cpp48
1 files changed, 40 insertions, 8 deletions
diff --git a/externals/grill/py/source/main.cpp b/externals/grill/py/source/main.cpp
index 8c46b037..657349e7 100644
--- a/externals/grill/py/source/main.cpp
+++ b/externals/grill/py/source/main.cpp
@@ -2,14 +2,14 @@
py/pyext - python external object for PD and MaxMSP
-Copyright (c)2002-2004 Thomas Grill (xovo@gmx.net)
+Copyright (c)2002-2004 Thomas Grill (gr@grrrr.org)
For information on usage and redistribution, and for a DISCLAIMER OF ALL
WARRANTIES, see the file, "license.txt," in this distribution.
*/
#include "main.h"
-
+#include <map>
static PyMethodDef StdOut_Methods[] =
{
@@ -17,6 +17,44 @@ static PyMethodDef StdOut_Methods[] =
{ NULL, NULL, }
};
+
+#ifdef FLEXT_THREADS
+typedef std::map<flext::thrid_t,PyThreadState *> PyThrMap;
+
+static PyInterpreterState *pystate = NULL;
+static PyThreadState *pythrmain = NULL;
+static PyThrMap pythrmap;
+
+PyThreadState *FindThreadState()
+{
+ flext::thrid_t id = flext::GetThreadId();
+ PyThrMap::iterator it = pythrmap.find(id);
+ if(it == pythrmap.end()) {
+ // Make new thread state
+ PyThreadState *st = PyThreadState_New(pystate);
+ pythrmap[id] = st;
+ return st;
+ }
+ else
+ return it->second;
+}
+
+void FreeThreadState()
+{
+ flext::thrid_t id = flext::GetThreadId();
+ PyThrMap::iterator it = pythrmap.find(id);
+ if(it != pythrmap.end()) {
+ // clear out any cruft from thread state object
+ PyThreadState_Clear(it->second);
+ // delete my thread state object
+ PyThreadState_Delete(it->second);
+ // delete from map
+ pythrmap.erase(it);
+ }
+}
+#endif
+
+
V py::lib_setup()
{
post("");
@@ -72,12 +110,6 @@ V py::lib_setup()
FLEXT_LIB_SETUP(py,py::lib_setup)
-#ifdef FLEXT_THREADS
-PyInterpreterState *py::pystate = NULL;
-PyThreadState *py::pythrmain = NULL;
-PyThrMap py::pythrmap;
-#endif
-
PyObject *py::module_obj = NULL;
PyObject *py::module_dict = NULL;