[PD-cvs] externals/grill/py/source main.h, 1.42, 1.43 py.cpp, 1.29, 1.30 pyargs.cpp, 1.19, 1.20 pybase.cpp, 1.3, 1.4 pybase.h, 1.3, 1.4 pyext.cpp, 1.37, 1.38 pyext.h, 1.25, 1.26 pymeth.cpp, 1.2, 1.3

Thomas Grill xovo at users.sourceforge.net
Tue Jul 19 15:18:35 CEST 2005


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

Modified Files:
	main.h py.cpp pyargs.cpp pybase.cpp pybase.h pyext.cpp pyext.h 
	pymeth.cpp 
Log Message:
better exception handling and error message
much better detach method handling (one thread for all object instances)
oops, forgot to code one branch
better definition of output values (atoms, lists, anythings)


Index: pyargs.cpp
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/py/source/pyargs.cpp,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -d -r1.19 -r1.20
*** pyargs.cpp	18 Jul 2005 18:03:12 -0000	1.19
--- pyargs.cpp	19 Jul 2005 13:18:33 -0000	1.20
***************
*** 193,196 ****
--- 193,201 ----
                  sym = pyObject_AsSymbol(s);
              }
+             else {
+                 // (symbol,atom) list
+             	lst(offs+rargc);           
+ 	    	    sym = getlist(lst.Atoms(),pValue,rargc);
+             }
  
              Py_DECREF(s);

Index: pymeth.cpp
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/py/source/pymeth.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** pymeth.cpp	18 Jul 2005 18:03:12 -0000	1.2
--- pymeth.cpp	19 Jul 2005 13:18:33 -0000	1.3
***************
*** 125,129 ****
  	void ResetFunction();
  
-     virtual bool thrcall(void *data);
      virtual void DumpOut(const t_symbol *sym,int argc,const t_atom *argv);
  
--- 125,128 ----
***************
*** 155,162 ****
  #ifdef FLEXT_THREADS
      FLEXT_CALLBACK_T(tick)
-     FLEXT_THREAD(threadworker)
- 	FLEXT_THREAD_X(work_wrapper)
- #else
- 	FLEXT_CALLBACK_X(work_wrapper)
  #endif
  };
--- 154,157 ----
***************
*** 182,186 ****
  	FLEXT_CADDMETHOD_(c,0,"set",m_set);
  
!   	FLEXT_CADDATTR_VAR1(c,"xlate",xlate);
    	FLEXT_CADDATTR_VAR1(c,"respond",respond);
  
--- 177,181 ----
  	FLEXT_CADDMETHOD_(c,0,"set",m_set);
  
!   	FLEXT_CADDATTR_VAR1(c,"py",xlate);
    	FLEXT_CADDATTR_VAR1(c,"respond",respond);
  
***************
*** 196,201 ****
  #ifdef FLEXT_THREADS
      FLEXT_ADDTIMER(stoptmr,tick);
-     // launch thread worker
-     FLEXT_CALLMETHOD(threadworker);
  #endif
  
--- 191,194 ----
***************
*** 437,443 ****
      ToOutAnything(GetOutAttr(),sym?sym:thisTag(),argc,argv);
  }
- 
- bool pymeth::thrcall(void *data)
- { 
-     return FLEXT_CALLMETHOD_X(work_wrapper,data);
- }
--- 430,431 ----

Index: pyext.h
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/py/source/pyext.h,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -d -r1.25 -r1.26
*** pyext.h	18 Jul 2005 18:03:12 -0000	1.25
--- pyext.h	19 Jul 2005 13:18:33 -0000	1.26
***************
*** 114,118 ****
  	bool call(const char *meth,int inlet,const t_symbol *s,int argc,const t_atom *argv);
  
-     virtual bool thrcall(void *data);
      virtual void callpy(PyObject *fun,PyObject *args);
      static bool stcallpy(PyObject *fun,PyObject *args);
--- 114,117 ----
***************
*** 149,156 ****
  #ifdef FLEXT_THREADS
      FLEXT_CALLBACK_T(tick)
-     FLEXT_THREAD(threadworker)
- 	FLEXT_THREAD_X(work_wrapper)
- #else
- 	FLEXT_CALLBACK_X(work_wrapper)
  #endif
  };
--- 148,151 ----

Index: pybase.h
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/py/source/pybase.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** pybase.h	18 Jul 2005 18:03:12 -0000	1.3
--- pybase.h	19 Jul 2005 13:18:33 -0000	1.4
***************
*** 149,153 ****
      }
  
!     virtual bool thrcall(void *data) = 0;
      virtual void callpy(PyObject *fun,PyObject *args) = 0;
  
--- 149,153 ----
      }
  
! //    virtual bool thrcall(void *data) = 0;
      virtual void callpy(PyObject *fun,PyObject *args) = 0;
  
***************
*** 162,172 ****
  protected:
  
- 	void work_wrapper(void *data); 
- 
  #ifdef FLEXT_THREADS
      bool qucall(PyObject *fun,PyObject *args);
!     void threadworker();
!     PyFifo qufifo;
!     ThrCond qucond;
      static PyThreadState *pythrsys;
  
--- 162,175 ----
  protected:
  
  #ifdef FLEXT_THREADS
+     static void thrworker(thr_params *data); 
+ 
      bool qucall(PyObject *fun,PyObject *args);
! 
!     static void quworker(thr_params *);
!     void erasethreads();
! 
!     static PyFifo qufifo;
!     static ThrCond qucond;
      static PyThreadState *pythrsys;
  

Index: pybase.cpp
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/py/source/pybase.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** pybase.cpp	18 Jul 2005 18:03:12 -0000	1.3
--- pybase.cpp	19 Jul 2005 13:18:33 -0000	1.4
***************
*** 57,60 ****
--- 57,63 ----
      }
  }
+ 
+ PyFifo pybase::qufifo;
+ flext::ThrCond pybase::qucond;
  #endif
  
***************
*** 168,171 ****
--- 171,177 ----
      // release global lock
      PyEval_ReleaseLock();
+ 
+     // launch thread worker
+     LaunchThread(quworker,NULL);
  #endif
  
***************
*** 183,187 ****
      : module(NULL)
  #ifdef FLEXT_THREADS
!     , shouldexit(false),thrcount(0),stoptick(0)
  #endif
  	, detach(0)
--- 189,194 ----
      : module(NULL)
  #ifdef FLEXT_THREADS
!     , thrcount(0)
!     , shouldexit(false),stoptick(0)
  #endif
  	, detach(0)
***************
*** 203,208 ****
--- 210,218 ----
  {
  #ifdef FLEXT_THREADS
+     erasethreads();
+ 
      shouldexit = true;
      qucond.Signal();
+ 
      if(thrcount) {
  		// Wait for a certain time
***************
*** 581,585 ****
              // each call a new thread
              if(!shouldexit) {
! 			    ret = thrcall(new work_data(pmeth,pargs));
  			    if(!ret) post("py/pyext - Failed to launch thread!");
  		    }
--- 591,598 ----
              // each call a new thread
              if(!shouldexit) {
!                 thr_params *p = new thr_params;
!                 p->cl = (flext_base *)this;
!                 p->var->_ext = new work_data(pmeth,pargs);
! 			    ret = LaunchThread(thrworker,p);
  			    if(!ret) post("py/pyext - Failed to launch thread!");
  		    }
***************
*** 610,640 ****
  }
  
- void pybase::work_wrapper(void *data)
- {
-     FLEXT_ASSERT(data);
- 
  #ifdef FLEXT_THREADS
! 	++thrcount;
! #endif
  
      PyThreadState *state = PyLock();
  
      // call worker
! 	work_data *w = (work_data *)data;
! 	docall(w->fun,w->args);
  	delete w;
  
      PyUnlock(state);
! 
! #ifdef FLEXT_THREADS
!     --thrcount;
! #endif
  }
  
- #ifdef FLEXT_THREADS
  bool pybase::qucall(PyObject *fun,PyObject *args)
  {
      FifoEl *el = qufifo.New();
!     el->Set(fun,args);
      qufifo.Put(el);
      qucond.Signal();
--- 623,648 ----
  }
  
  #ifdef FLEXT_THREADS
! void pybase::thrworker(thr_params *p)
! {
!     FLEXT_ASSERT(p);
!     pybase *th = (pybase *)p->cl;
! 	work_data *w = (work_data *)p->var->_ext;
  
+ 	++th->thrcount; // \todo this should be atomic
      PyThreadState *state = PyLock();
  
      // call worker
! 	th->docall(w->fun,w->args);
  	delete w;
  
      PyUnlock(state);
!     --th->thrcount; // \todo this should be atomic
  }
  
  bool pybase::qucall(PyObject *fun,PyObject *args)
  {
      FifoEl *el = qufifo.New();
!     el->Set(this,fun,args);
      qufifo.Put(el);
      qucond.Signal();
***************
*** 642,649 ****
  }
  
! void pybase::threadworker()
  {
-    	++thrcount;
- 
      FifoEl *el;
      PyThreadState *my = FindThreadState(),*state;
--- 650,655 ----
  }
  
! void pybase::quworker(thr_params *)
  {
      FifoEl *el;
      PyThreadState *my = FindThreadState(),*state;
***************
*** 651,669 ****
      for(;;) {
          while(el = qufifo.Get()) {
!         	++thrcount;
              state = PyLock(my);
!             docall(el->fun,el->args);
              Py_XDECREF(el->fun);
              Py_XDECREF(el->args);
              PyUnlock(state);
              qufifo.Free(el);
-             --thrcount;
          }
!         if(shouldexit) 
!             break;
!         else
!             qucond.Wait();
      }
  
      state = PyLock(my);
      // unref remaining Python objects
--- 657,674 ----
      for(;;) {
          while(el = qufifo.Get()) {
!         	++el->th->thrcount; // \todo this should be atomic
              state = PyLock(my);
!             el->th->docall(el->fun,el->args);
              Py_XDECREF(el->fun);
              Py_XDECREF(el->args);
              PyUnlock(state);
+             --el->th->thrcount; // \todo this should be atomic
              qufifo.Free(el);
          }
!         qucond.Wait();
      }
  
+     // we never end
+ #if 0
      state = PyLock(my);
      // unref remaining Python objects
***************
*** 674,679 ****
      }
      PyUnlock(state);
  
!     --thrcount;
  }
  #endif
--- 679,700 ----
      }
      PyUnlock(state);
+ #endif
+ }
  
! void pybase::erasethreads()
! {
!     PyFifo tmp;
!     FifoEl *el;
!     while(el = qufifo.Get()) {
!         if(el->th == this) {
!             Py_XDECREF(el->fun);
!             Py_XDECREF(el->args);
!             qufifo.Free(el);
!         }
!         else
!             tmp.Put(el);
!     }
!     // Push back
!     while(el = tmp.Get()) qufifo.Put(el);
  }
  #endif

Index: pyext.cpp
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/py/source/pyext.cpp,v
retrieving revision 1.37
retrieving revision 1.38
diff -C2 -d -r1.37 -r1.38
*** pyext.cpp	18 Jul 2005 18:03:12 -0000	1.37
--- pyext.cpp	19 Jul 2005 13:18:33 -0000	1.38
***************
*** 42,46 ****
  	FLEXT_CADDMETHOD_(c,0,"set",m_set);
  
!   	FLEXT_CADDATTR_VAR1(c,"xlate",xlate);
    	FLEXT_CADDATTR_VAR1(c,"respond",respond);
  
--- 42,46 ----
  	FLEXT_CADDMETHOD_(c,0,"set",m_set);
  
!   	FLEXT_CADDATTR_VAR1(c,"py",xlate);
    	FLEXT_CADDATTR_VAR1(c,"respond",respond);
  
***************
*** 121,126 ****
  #ifdef FLEXT_THREADS
      FLEXT_ADDTIMER(stoptmr,tick);
-     // launch thread worker
-     FLEXT_CALLMETHOD(threadworker);
  #endif
  
--- 121,124 ----
***************
*** 630,636 ****
      ToOutAnything(GetOutAttr(),sym?sym:thisTag(),argc,argv);
  }
- 
- bool pyext::thrcall(void *data)
- { 
-     return FLEXT_CALLMETHOD_X(work_wrapper,data);
- }
--- 628,629 ----

Index: main.h
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/py/source/main.h,v
retrieving revision 1.42
retrieving revision 1.43
diff -C2 -d -r1.42 -r1.43
*** main.h	8 Jul 2005 14:30:31 -0000	1.42
--- main.h	19 Jul 2005 13:18:33 -0000	1.43
***************
*** 26,34 ****
  
  
  class FifoEl
      : public Fifo::Cell
  {
  public:
!     void Set(PyObject *f,PyObject *a) { fun = f,args = a; }
      PyObject *fun,*args;
  };
--- 26,37 ----
  
  
+ class pybase;
+ 
  class FifoEl
      : public Fifo::Cell
  {
  public:
!     void Set(pybase *t,PyObject *f,PyObject *a) { th = t,fun = f,args = a; }
!     pybase *th;
      PyObject *fun,*args;
  };

Index: py.cpp
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/py/source/py.cpp,v
retrieving revision 1.29
retrieving revision 1.30
diff -C2 -d -r1.29 -r1.30
*** py.cpp	18 Jul 2005 18:03:12 -0000	1.29
--- py.cpp	19 Jul 2005 13:18:33 -0000	1.30
***************
*** 48,52 ****
  	bool ResetFunction();
  
-     virtual bool thrcall(void *data);
      virtual void DumpOut(const t_symbol *sym,int argc,const t_atom *argv);
  
--- 48,51 ----
***************
*** 78,85 ****
  #ifdef FLEXT_THREADS
      FLEXT_CALLBACK_T(tick)
-     FLEXT_THREAD(threadworker)
- 	FLEXT_THREAD_X(work_wrapper)
- #else
- 	FLEXT_CALLBACK_X(work_wrapper)
  #endif
  };
--- 77,80 ----
***************
*** 105,109 ****
  	FLEXT_CADDMETHOD_(c,0,"set",m_set);
  
!   	FLEXT_CADDATTR_VAR1(c,"xlate",xlate);
    	FLEXT_CADDATTR_VAR1(c,"respond",respond);
  }
--- 100,104 ----
  	FLEXT_CADDMETHOD_(c,0,"set",m_set);
  
!   	FLEXT_CADDATTR_VAR1(c,"py",xlate);
    	FLEXT_CADDATTR_VAR1(c,"respond",respond);
  }
***************
*** 117,122 ****
  #ifdef FLEXT_THREADS
      FLEXT_ADDTIMER(stoptmr,tick);
-     // launch thread worker
-     FLEXT_CALLMETHOD(threadworker);
  #endif
  
--- 112,115 ----
***************
*** 427,433 ****
      ToOutAnything(GetOutAttr(),sym?sym:thisTag(),argc,argv);
  }
- 
- bool pyobj::thrcall(void *data)
- { 
-     return FLEXT_CALLMETHOD_X(work_wrapper,data);
- }
--- 420,421 ----





More information about the Pd-cvs mailing list