[PD-cvs] externals/grill/py/source main.cpp,1.25,1.26 main.h,1.32,1.33

Thomas Grill xovo at users.sourceforge.net
Sun Mar 6 05:57:35 CET 2005


Update of /cvsroot/pure-data/externals/grill/py/source
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11209/source

Modified Files:
	main.cpp main.h 
Log Message:
use new flext fifo
use lock count instead of message queuing to avoid py->py messaging deadlock


Index: main.cpp
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/py/source/main.cpp,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -d -r1.25 -r1.26
*** main.cpp	27 Feb 2005 04:57:47 -0000	1.25
--- main.cpp	6 Mar 2005 04:57:32 -0000	1.26
***************
*** 511,535 ****
  bool py::qucall(PyObject *fun,PyObject *args)
  {
!     if(qufifo.Push(fun,args)) {
!         qucond.Signal();
!         return true;
!     }
!     else
!         return false;
  }
  
  void py::threadworker()
  {
!     PyObject *fun,*args;
      PyThreadState *state;
  
      while(!shouldexit) {
!         state = PyLock();
!         while(qufifo.Pop(fun,args)) {
!             callpy(fun,args);
!             Py_XDECREF(fun);
!             Py_XDECREF(args);
          }
-         PyUnlock(state);
          qucond.Wait();
      }
--- 511,535 ----
  bool py::qucall(PyObject *fun,PyObject *args)
  {
!     FifoEl *el = qufifo.New();
!     el->Set(fun,args);
!     qufifo.Put(el);
!     qucond.Signal();
!     return true;
  }
  
  void py::threadworker()
  {
!     FifoEl *el;
      PyThreadState *state;
  
      while(!shouldexit) {
!         while(el = qufifo.Get()) {
!             state = PyLock();
!             callpy(el->fun,el->args);
!             Py_XDECREF(el->fun);
!             Py_XDECREF(el->args);
!             PyUnlock(state);
!             qufifo.Free(el);
          }
          qucond.Wait();
      }
***************
*** 537,545 ****
      state = PyLock();
      // unref remaining Python objects
!     while(qufifo.Pop(fun,args)) {
!         Py_XDECREF(fun);
!         Py_XDECREF(args);
      }
- 
      PyUnlock(state);
  }
--- 537,545 ----
      state = PyLock();
      // unref remaining Python objects
!     while(el = qufifo.Get()) {
!         Py_XDECREF(el->fun);
!         Py_XDECREF(el->args);
!         qufifo.Free(el);
      }
      PyUnlock(state);
  }
***************
*** 576,611 ****
      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;
- }
--- 576,577 ----

Index: main.h
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/py/source/main.h,v
retrieving revision 1.32
retrieving revision 1.33
diff -C2 -d -r1.32 -r1.33
*** main.h	27 Feb 2005 04:57:47 -0000	1.32
--- main.h	6 Mar 2005 04:57:32 -0000	1.33
***************
*** 14,17 ****
--- 14,18 ----
  #include "pyprefix.h"
  #include "pysymbol.h"
+ #include <flcontainers.h>
  
  #if FLEXT_OS == FLEXT_LINUX || FLEXT_OS == FLEXT_IRIX
***************
*** 29,51 ****
  
  
! class Fifo
  {
- 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;
  };
  
  
  class py:
--- 30,43 ----
  
  
! 
! class FifoEl
!     : public Fifo::Cell
  {
  public:
!     void Set(PyObject *f,PyObject *a) { fun = f,args = a; }
!     PyObject *fun,*args;
  };
  
+ typedef PooledFifo<FifoEl> PyFifo;
  
  class py:
***************
*** 142,146 ****
      bool qucall(PyObject *fun,PyObject *args);
      void threadworker();
!     Fifo qufifo;
      ThrCond qucond;
  
--- 134,138 ----
      bool qucall(PyObject *fun,PyObject *args);
      void threadworker();
!     PyFifo qufifo;
      ThrCond qucond;
  





More information about the Pd-cvs mailing list