aboutsummaryrefslogtreecommitdiff
path: root/externals/grill
diff options
context:
space:
mode:
Diffstat (limited to 'externals/grill')
-rw-r--r--externals/grill/py/source/main.cpp68
-rw-r--r--externals/grill/py/source/main.h24
2 files changed, 25 insertions, 67 deletions
diff --git a/externals/grill/py/source/main.cpp b/externals/grill/py/source/main.cpp
index a0919132..feabfde1 100644
--- a/externals/grill/py/source/main.cpp
+++ b/externals/grill/py/source/main.cpp
@@ -510,37 +510,37 @@ void py::work_wrapper(void *data)
#ifdef FLEXT_THREADS
bool py::qucall(PyObject *fun,PyObject *args)
{
- if(qufifo.Push(fun,args)) {
- qucond.Signal();
- return true;
- }
- else
- return false;
+ FifoEl *el = qufifo.New();
+ el->Set(fun,args);
+ qufifo.Put(el);
+ qucond.Signal();
+ return true;
}
void py::threadworker()
{
- PyObject *fun,*args;
+ FifoEl *el;
PyThreadState *state;
while(!shouldexit) {
- state = PyLock();
- while(qufifo.Pop(fun,args)) {
- callpy(fun,args);
- Py_XDECREF(fun);
- Py_XDECREF(args);
+ while(el = qufifo.Get()) {
+ state = PyLock();
+ callpy(el->fun,el->args);
+ Py_XDECREF(el->fun);
+ Py_XDECREF(el->args);
+ PyUnlock(state);
+ qufifo.Free(el);
}
- PyUnlock(state);
qucond.Wait();
}
state = PyLock();
// unref remaining Python objects
- while(qufifo.Pop(fun,args)) {
- Py_XDECREF(fun);
- Py_XDECREF(args);
+ while(el = qufifo.Get()) {
+ Py_XDECREF(el->fun);
+ Py_XDECREF(el->args);
+ qufifo.Free(el);
}
-
PyUnlock(state);
}
#endif
@@ -575,37 +575,3 @@ bool py::collect()
}
return true;
}
-
-Fifo::~Fifo()
-{
- FifoEl *el = head;
- head = tail = NULL; // reset it, in case there's a thread wanting to Pop
- while(el) {
- FifoEl *n = el->nxt;
- delete el;
- el = n;
- }
-}
-
-bool Fifo::Push(PyObject *f,PyObject *a)
-{
- FifoEl *el = new FifoEl;
- el->fun = f;
- el->args = a;
- if(tail) tail->nxt = el;
- else head = el;
- tail = el;
- return true;
-}
-
-bool Fifo::Pop(PyObject *&f,PyObject *&a)
-{
- if(!head) return false;
- FifoEl *el = head;
- head = el->nxt;
- f = el->fun;
- a = el->args;
- if(tail == el) tail = NULL;
- delete el;
- return true;
-}
diff --git a/externals/grill/py/source/main.h b/externals/grill/py/source/main.h
index e1ae64a4..cd1c3736 100644
--- a/externals/grill/py/source/main.h
+++ b/externals/grill/py/source/main.h
@@ -13,6 +13,7 @@ WARRANTIES, see the file, "license.txt," in this distribution.
#include "pyprefix.h"
#include "pysymbol.h"
+#include <flcontainers.h>
#if FLEXT_OS == FLEXT_LINUX || FLEXT_OS == FLEXT_IRIX
#include <unistd.h>
@@ -28,25 +29,16 @@ WARRANTIES, see the file, "license.txt," in this distribution.
#define PY_STOP_TICK 10 // ms
-class Fifo
+
+class FifoEl
+ : public Fifo::Cell
{
-protected:
- struct FifoEl {
- PyObject *fun;
- PyObject *args;
- FifoEl *nxt;
- };
public:
- Fifo(): head(NULL),tail(NULL) {}
- ~Fifo();
-
- bool Push(PyObject *f,PyObject *a);
- bool Pop(PyObject *&f,PyObject *&a);
-
-protected:
- FifoEl *head,*tail;
+ void Set(PyObject *f,PyObject *a) { fun = f,args = a; }
+ PyObject *fun,*args;
};
+typedef PooledFifo<FifoEl> PyFifo;
class py:
public flext_base
@@ -141,7 +133,7 @@ private:
#ifdef FLEXT_THREADS
bool qucall(PyObject *fun,PyObject *args);
void threadworker();
- Fifo qufifo;
+ PyFifo qufifo;
ThrCond qucond;
static PyThreadState *FindThreadState();