aboutsummaryrefslogtreecommitdiff
path: root/externals/grill/py/source/main.cpp
diff options
context:
space:
mode:
authorThomas Grill <xovo@users.sourceforge.net>2005-03-08 04:59:25 +0000
committerThomas Grill <xovo@users.sourceforge.net>2005-03-08 04:59:25 +0000
commit0bd834874c00c5fc5ed251c9fdbff68608d44eb5 (patch)
treea427b34472a5d4976bbee3b3d083ce432bdb80b1 /externals/grill/py/source/main.cpp
parentdfcbb9904402efc8f0deec2a16bd905b911da0aa (diff)
pass timeout argument to stop method
fixes for detached mode fixes for detached operation and single-threaded version use lock count instead of message queuing to avoid py->py messaging deadlock use new flext fifo svn path=/trunk/; revision=2602
Diffstat (limited to 'externals/grill/py/source/main.cpp')
-rw-r--r--externals/grill/py/source/main.cpp48
1 files changed, 31 insertions, 17 deletions
diff --git a/externals/grill/py/source/main.cpp b/externals/grill/py/source/main.cpp
index feabfde1..01dc0afa 100644
--- a/externals/grill/py/source/main.cpp
+++ b/externals/grill/py/source/main.cpp
@@ -157,18 +157,19 @@ void py::Setup(t_classid c)
#endif
}
-py::py():
- module(NULL),
- detach(0),shouldexit(false),thrcount(0),
- stoptick(0)
+py::py()
+ : module(NULL),detach(0)
+#ifdef FLEXT_THREADS
+ , shouldexit(false),thrcount(0),stoptick(0)
+#endif
{
PyThreadState *state = PyLock();
Py_INCREF(module_obj);
PyUnlock(state);
+#ifdef FLEXT_THREADS
FLEXT_ADDTIMER(stoptmr,tick);
-#ifdef FLEXT_THREADS
// launch thread worker
FLEXT_CALLMETHOD(threadworker);
#endif
@@ -176,27 +177,29 @@ py::py():
py::~py()
{
- shouldexit = true;
+ PyThreadState *state = PyLock();
+ Py_XDECREF(module_obj);
+ PyUnlock(state);
+}
+void py::Exit()
+{
#ifdef FLEXT_THREADS
+ shouldexit = true;
qucond.Signal();
-
if(thrcount) {
// Wait for a certain time
- for(int i = 0; i < (PY_STOP_WAIT/PY_STOP_TICK) && thrcount; ++i) Sleep((float)(PY_STOP_TICK/1000.));
+ for(int i = 0; i < (PY_STOP_WAIT/PY_STOP_TICK) && thrcount; ++i) Sleep(PY_STOP_TICK/1000.f);
// Wait forever
post("%s - Waiting for thread termination!",thisName());
- while(thrcount) Sleep(0.01f);
+ while(thrcount) Sleep(PY_STOP_TICK/1000.f);
post("%s - Okay, all threads have terminated",thisName());
}
#endif
- PyThreadState *state = PyLock();
- Py_XDECREF(module_obj);
- PyUnlock(state);
+ flext_base::Exit();
}
-
void py::GetDir(PyObject *obj,AtomList &lst)
{
if(obj) {
@@ -475,7 +478,6 @@ bool py::gencall(PyObject *pmeth,PyObject *pargs)
// put call into queue
ret = qucall(pmeth,pargs);
break;
-#endif
case 2:
// each call a new thread
if(!shouldexit) {
@@ -483,8 +485,9 @@ bool py::gencall(PyObject *pmeth,PyObject *pargs)
if(!ret) post("%s - Failed to launch thread!",thisName());
}
break;
+#endif
default:
- FLEXT_ASSERT(false);
+ post("%s - Unknown detach mode",thisName());
}
return ret;
}
@@ -493,7 +496,9 @@ void py::work_wrapper(void *data)
{
FLEXT_ASSERT(data);
+#ifdef FLEXT_THREADS
++thrcount;
+#endif
PyThreadState *state = PyLock();
@@ -504,7 +509,9 @@ void py::work_wrapper(void *data)
PyUnlock(state);
+#ifdef FLEXT_THREADS
--thrcount;
+#endif
}
#ifdef FLEXT_THREADS
@@ -522,16 +529,22 @@ void py::threadworker()
FifoEl *el;
PyThreadState *state;
- while(!shouldexit) {
+ ++thrcount;
+ for(;;) {
while(el = qufifo.Get()) {
+ ++thrcount;
state = PyLock();
callpy(el->fun,el->args);
Py_XDECREF(el->fun);
Py_XDECREF(el->args);
PyUnlock(state);
qufifo.Free(el);
+ --thrcount;
}
- qucond.Wait();
+ if(shouldexit)
+ break;
+ else
+ qucond.Wait();
}
state = PyLock();
@@ -542,6 +555,7 @@ void py::threadworker()
qufifo.Free(el);
}
PyUnlock(state);
+ --thrcount;
}
#endif