[PD-cvs] externals/grill/flext/source flatom.cpp,1.9,1.10 flbind.cpp,1.14,1.15 flclass.h,1.44,1.45 flmeth.cpp,1.10,1.11 flqueue.cpp,1.16,1.17

Thomas Grill xovo at users.sourceforge.net
Sat Sep 11 06:00:43 CEST 2004


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

Modified Files:
	flatom.cpp flbind.cpp flclass.h flmeth.cpp flqueue.cpp 
Log Message:
 ""

Index: flqueue.cpp
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/flext/source/flqueue.cpp,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** flqueue.cpp	21 Jun 2004 13:58:19 -0000	1.16
--- flqueue.cpp	11 Sep 2004 04:00:41 -0000	1.17
***************
*** 20,23 ****
--- 20,24 ----
  #include "flinternal.h"
  
+ 
  #ifdef FLEXT_THREADS
  //! Thread id of message queue thread
***************
*** 25,72 ****
  #endif
  
  class qmsg
  {
  public:
!     qmsg(flext_base *b): nxt(NULL),th(b),tp(tp_none) {}
!     ~qmsg();
! 
!     qmsg *nxt;
  
!     void Clear();
  
!     void SetBang(int o) { Clear(); out = o; tp = tp_bang; }
!     void SetFloat(int o,float f) { Clear(); out = o; tp = tp_float; _float = f; }
!     void SetInt(int o,int i) { Clear(); out = o; tp = tp_int; _int = i; }
!     void SetSymbol(int o,const t_symbol *s) { Clear(); out = o; tp = tp_sym; _sym = s; }
!     void SetList(int o,int argc,const t_atom *argv) { Clear(); out = o; tp = tp_list; _list.argc = argc,_list.argv = flext::CopyList(argc,argv); }
!     void SetAny(int o,const t_symbol *s,int argc,const t_atom *argv) { Clear(); out = o; tp = tp_any; _any.s = s,_any.argc = argc,_any.argv = flext::CopyList(argc,argv); }
  
      flext_base *th;
      int out;
!     enum { tp_none,tp_bang,tp_float,tp_int,tp_sym,tp_list,tp_any } tp;
!     union {
!         float _float;
!         int _int;
!         const t_symbol *_sym;
!         struct { int argc; t_atom *argv; } _list;
!         struct { const t_symbol *s; int argc; t_atom *argv; } _any;
!     };
  };
  
! qmsg::~qmsg() 
! { 
!     Clear();
!     if(nxt) delete nxt; 
! }
  
! void qmsg::Clear() 
! { 
!     if(tp == tp_list) { if(_list.argv) delete[] _list.argv; }
!     else if(tp == tp_any) { if(_any.argv) delete[] _any.argv; }
!     tp = tp_none;
! }
  
- static volatile int qcnt = 0;
- static qmsg *volatile qhead = NULL,*volatile qtail = NULL;
  
  #ifdef FLEXT_QTHR
--- 26,177 ----
  #endif
  
+ 
+ #define QUEUE_LENGTH 256
+ #define QUEUE_ATOMS 1024
+ 
  class qmsg
  {
  public:
!     void Set(flext_base *t,int o,const t_symbol *s,int ac,const t_atom *av) { th = t,out = o,sym = s,argc = ac,argv = av; }
  
!     // \note PD lock must already be held by caller
!     void Send() const
!     {
!         if(out < 0)
!             // message to self
!             th->m_methodmain(-1-out,sym,argc,argv); 
!         else
!             // message to outlet
!             th->ToSysAnything(out,sym,argc,argv);
!     }
  
!     int Args() const { return argc; }
  
+ private:
      flext_base *th;
      int out;
!     const t_symbol *sym; 
!     int argc; 
!     const t_atom *argv;
  };
  
! // _should_ work without locks.... have yet to check if it really does....
! class Queue:
!     public flext
! {
! public:
!     Queue()
!     {
!         qhead = qtail = 0;
!         ahead = atail = 0;
!     }
  
!     bool Empty() const { return qhead == qtail; }
! 
!     int Count() const 
!     { 
!         int c = qtail-qhead;
!         return c >= 0?c:c+QUEUE_LENGTH; 
!     }
! 
!     const qmsg &Head() { return lst[qhead]; }
! 
!     void Pop() 
!     { 
!         PopAtoms(Head().Args());
!         qhead = (qhead+1)%QUEUE_LENGTH;
!     }
! 
!     void Push(flext_base *th,int o) // bang
!     { 
!         Set(th,o,sym_bang,0,NULL); 
!     }
! 
!     void Push(flext_base *th,int o,float dt) 
!     { 
!         t_atom *at = GetAtoms(1); 
!         SetFloat(*at,dt);
!         Set(th,o,sym_float,1,at); 
!     }
! 
!     void Push(flext_base *th,int o,int dt) 
!     { 
!         t_atom *at = GetAtoms(1); 
!         SetInt(*at,dt);
! #if FLEXT_SYS == FLEXT_SYS_PD
!         const t_symbol *sym = sym_float;
! #elif FLEXT_SYS == FLEXT_SYS_MAX
!         const t_symbol *sym = sym_int;
! #else
! #error Not implemented!
! #endif
!         Set(th,o,sym,1,at); 
!     }
! 
!     void Push(flext_base *th,int o,const t_symbol *dt) 
!     { 
!         t_atom *at = GetAtoms(1); 
!         SetSymbol(*at,dt);
!         Set(th,o,sym_symbol,1,at); 
!     }
! 
!     void Push(flext_base *th,int o,int argc,const t_atom *argv) 
!     {
!         t_atom *at = GetAtoms(argc);
!         memcpy(at,argv,argc*sizeof(t_atom));
!         Set(th,o,sym_list,argc,at); 
!     }
! 
!     void Push(flext_base *th,int o,const t_symbol *sym,int argc,const t_atom *argv) 
!     { 
!         t_atom *at = GetAtoms(argc);
!         memcpy(at,argv,argc*sizeof(t_atom));
!         Set(th,o,sym,argc,at); 
!     }
! 
! protected:
!     void Set(flext_base *th,int o,const t_symbol *sym,int argc,const t_atom *argv)
!     {
!         FLEXT_ASSERT(Count() < QUEUE_LENGTH-1);
!         lst[qtail].Set(th,o,sym,argc,argv);
!         qtail = (qtail+1)%QUEUE_LENGTH;
!     }
! 
!     int CntAtoms() const 
!     { 
!         int c = atail-ahead;
!         return c >= 0?c:c+QUEUE_ATOMS;
!     }
! 
!     // must return contiguous region
!     t_atom *GetAtoms(int argc)
!     {
!         // \todo check for available space
! 
!         if(atail+argc >= QUEUE_ATOMS) {
!             atail = argc;
!             return atoms;
!         }
!         else {
!             t_atom *at = atoms+atail;
!             atail += argc;
!             return at;
!         }
!     }
! 
!     void PopAtoms(int argc) 
!     {
!         const int p = ahead+argc;
!         ahead = p >= QUEUE_ATOMS?argc:p;
!     }
! 
!     int qhead,qtail;
!     qmsg lst[QUEUE_LENGTH];
!     int ahead,atail;
!     t_atom atoms[QUEUE_ATOMS];
! };
! 
! static Queue queue;
  
  
  #ifdef FLEXT_QTHR
***************
*** 76,86 ****
  #endif
  
- #ifdef FLEXT_THREADS
- static flext::ThrMutex qmutex;
- #endif
  
  #define CHUNK 10
  
! static void QWork(bool qlock,bool syslock)
  {
      for(;;) {
--- 181,188 ----
  #endif
  
  
  #define CHUNK 10
  
! static void QWork(bool syslock)
  {
      for(;;) {
***************
*** 89,93 ****
          // On the other hand, if new queue elements are added by the methods called
          // in the loop, these will be sent in the next tick to avoid recursion overflow.
!         int qc = qcnt;
          if(!qc) break;
  
--- 191,195 ----
          // On the other hand, if new queue elements are added by the methods called
          // in the loop, these will be sent in the next tick to avoid recursion overflow.
!         int qc = queue.Count();
          if(!qc) break;
  
***************
*** 96,168 ****
      #endif
  
!         for(int i = 0; i < qc && qhead; ++i) {
!     #ifdef FLEXT_THREADS
!             if(qlock) qmutex.Lock();
!     #endif
!             qmsg *m = qhead;
!             qcnt--;
!             qhead = m->nxt;
!             if(!qhead) qtail = NULL;
!             m->nxt = NULL;
!     #ifdef FLEXT_THREADS
!             if(qlock) qmutex.Unlock();
!     #endif
! 
!             if(m->out < 0) {
!                 // message to self
! 
!                 const int n = -1-m->out;
!                 t_atom tmp;
! 
!                 switch(m->tp) {
!                 case qmsg::tp_bang: 
!                     m->th->m_methodmain(n,flext::sym_bang,0,&tmp); 
!                     break;
!                 case qmsg::tp_float: 
!                     flext::SetFloat(tmp,m->_float);
!                     m->th->m_methodmain(n,flext::sym_float,1,&tmp); 
!                     break;
!                 case qmsg::tp_int: 
!                     flext::SetInt(tmp,m->_int);
!     #if FLEXT_SYS == FLEXT_SYS_PD
!                     m->th->m_methodmain(n,flext::sym_float,1,&tmp); 
!     #elif FLEXT_SYS == FLEXT_SYS_MAX
!                     m->th->m_methodmain(n,flext::sym_int,1,&tmp); 
!     #else
!     #error Not implemented!
!     #endif
!                 case qmsg::tp_sym: 
!                     flext::SetSymbol(tmp,m->_sym);
!                     m->th->m_methodmain(n,flext::sym_symbol,1,&tmp); 
!                     break;
!                 case qmsg::tp_list: 
!                     m->th->m_methodmain(n,flext::sym_list,m->_list.argc,m->_list.argv); 
!                     break;
!                 case qmsg::tp_any: 
!                     m->th->m_methodmain(n,m->_any.s,m->_any.argc,m->_any.argv); 
!                     break;
!         #ifdef FLEXT_DEBUG
!                 default: ERRINTERNAL();
!         #endif
!                 }
!             }
!             else {
!                 // message to outlet
! 
!                 switch(m->tp) {
!                 case qmsg::tp_bang: m->th->ToSysBang(m->out); break;
!                 case qmsg::tp_float: m->th->ToSysFloat(m->out,m->_float); break;
!                 case qmsg::tp_int: m->th->ToSysInt(m->out,m->_int); break;
!                 case qmsg::tp_sym: m->th->ToSysSymbol(m->out,m->_sym); break;
!                 case qmsg::tp_list: m->th->ToSysList(m->out,m->_list.argc,m->_list.argv); break;
!                 case qmsg::tp_any: m->th->ToSysAnything(m->out,m->_any.s,m->_any.argc,m->_any.argv); break;
!         #ifdef FLEXT_DEBUG
!                 default: ERRINTERNAL();
!         #endif
!                 }
!             }
! 
!             // delete processed queue element
!             delete m;
          } // inner loop
  
--- 198,204 ----
      #endif
  
!         for(int i = 0; i < qc; ++i) {
!             queue.Head().Send();
!             queue.Pop();
          } // inner loop
  
***************
*** 171,175 ****
      #endif
  
!     } // for(;;)
  }
  
--- 207,211 ----
      #endif
  
!     }
  }
  
***************
*** 182,190 ****
  {
  #endif
- //  post("qtick");
  #ifdef FLEXT_THREADS
      FLEXT_ASSERT(flext::IsSystemThread());
  #endif
!     QWork(true,false);
  }
  #endif
--- 218,225 ----
  {
  #endif
  #ifdef FLEXT_THREADS
      FLEXT_ASSERT(flext::IsSystemThread());
  #endif
!     QWork(false);
  }
  #endif
***************
*** 202,229 ****
      }
  #endif
! #ifdef FLEXT_THREADS
!     qmutex.Lock();
! #endif
!     while(qcnt) QWork(false,false);
! #ifdef FLEXT_THREADS
!     qmutex.Unlock();
! #endif
  }
  
! static void Queue(qmsg *m)
  {
- //  post("Queue");
- 
- #ifdef FLEXT_THREADS
-     qmutex.Lock();
- #endif
-     if(qtail) qtail->nxt = m;
-     else qhead = m;
-     qtail = m;
-     qcnt++;
- #ifdef FLEXT_THREADS
-     qmutex.Unlock();
- #endif
- 
  #if FLEXT_SYS == FLEXT_SYS_PD
      #ifdef FLEXT_QTHR
--- 237,246 ----
      }
  #endif
! 
!     while(!queue.Empty()) QWork(false);
  }
  
! static void Trigger()
  {
  #if FLEXT_SYS == FLEXT_SYS_PD
      #ifdef FLEXT_QTHR
***************
*** 250,254 ****
      for(;;) {
          qthrcond.Wait();
!         QWork(true,true);
      }
  }
--- 267,271 ----
      for(;;) {
          qthrcond.Wait();
!         QWork(true);
      }
  }
***************
*** 261,268 ****
      else started = true;
  
-     // message queue ticker
-     qhead = qtail = NULL;
-     qcnt = 0;
- 
  #ifdef FLEXT_QTHR
      LaunchThread(QWorker,NULL);
--- 278,281 ----
***************
*** 278,362 ****
  void flext_base::ToQueueBang(int o) const 
  {
!     FLEXT_ASSERT(o >= 0);
!         qmsg *m = new qmsg(const_cast<flext_base *>(this)); 
!     m->SetBang(o);
!     Queue(m);
  }
  
  void flext_base::ToQueueFloat(int o,float f) const
  {
!     FLEXT_ASSERT(o >= 0);
!     qmsg *m = new qmsg(const_cast<flext_base *>(this)); 
!     m->SetFloat(o,f);
!     Queue(m);
  }
  
  void flext_base::ToQueueInt(int o,int f) const
  {
!     FLEXT_ASSERT(o >= 0);
!     qmsg *m = new qmsg(const_cast<flext_base *>(this)); 
!     m->SetInt(o,f);
!     Queue(m);
  }
  
  void flext_base::ToQueueSymbol(int o,const t_symbol *s) const
  {
!     FLEXT_ASSERT(o >= 0);
!     qmsg *m = new qmsg(const_cast<flext_base *>(this)); 
!     m->SetSymbol(o,s);
!     Queue(m);
  }
  
  void flext_base::ToQueueList(int o,int argc,const t_atom *argv) const
  {
!     FLEXT_ASSERT(o >= 0);
!     qmsg *m = new qmsg(const_cast<flext_base *>(this)); 
!     m->SetList(o,argc,argv);
!     Queue(m);
  }
  
  void flext_base::ToQueueAnything(int o,const t_symbol *s,int argc,const t_atom *argv) const
  {
!     FLEXT_ASSERT(o >= 0);
!     qmsg *m = new qmsg(const_cast<flext_base *>(this)); 
!     m->SetAny(o,s,argc,argv);
!     Queue(m);
! }
! 
! 
! void flext_base::ToSelfBang(int n) const 
! {
!     FLEXT_ASSERT(n >= 0);
!     ToQueueBang(-1-n);
! }
! 
! void flext_base::ToSelfFloat(int n,float f) const
! {
!     FLEXT_ASSERT(n >= 0);
!     ToQueueFloat(-1-n,f);
! }
! 
! void flext_base::ToSelfInt(int n,int f) const
! {
!     FLEXT_ASSERT(n >= 0);
!     ToQueueInt(-1-n,f);
! }
! 
! void flext_base::ToSelfSymbol(int n,const t_symbol *s) const
! {
!     FLEXT_ASSERT(n >= 0);
!     ToQueueSymbol(-1-n,s);
! }
! 
! void flext_base::ToSelfList(int n,int argc,const t_atom *argv) const
! {
!     FLEXT_ASSERT(n >= 0);
!     ToQueueList(-1-n,argc,argv);
! }
! 
! void flext_base::ToSelfAnything(int n,const t_symbol *s,int argc,const t_atom *argv) const
! {
!     FLEXT_ASSERT(n >= 0);
!     ToQueueAnything(-1-n,s,argc,argv);
  }
- 
--- 291,325 ----
  void flext_base::ToQueueBang(int o) const 
  {
!     queue.Push(const_cast<flext_base *>(this),o);
!     Trigger();
  }
  
  void flext_base::ToQueueFloat(int o,float f) const
  {
!     queue.Push(const_cast<flext_base *>(this),o,f);
!     Trigger();
  }
  
  void flext_base::ToQueueInt(int o,int f) const
  {
!     queue.Push(const_cast<flext_base *>(this),o,f);
!     Trigger();
  }
  
  void flext_base::ToQueueSymbol(int o,const t_symbol *s) const
  {
!     queue.Push(const_cast<flext_base *>(this),o,s);
!     Trigger();
  }
  
  void flext_base::ToQueueList(int o,int argc,const t_atom *argv) const
  {
!     queue.Push(const_cast<flext_base *>(this),o,argc,argv);
!     Trigger();
  }
  
  void flext_base::ToQueueAnything(int o,const t_symbol *s,int argc,const t_atom *argv) const
  {
!     queue.Push(const_cast<flext_base *>(this),o,s,argc,argv);
!     Trigger();
  }

Index: flbind.cpp
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/flext/source/flbind.cpp,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** flbind.cpp	21 Jun 2004 13:58:19 -0000	1.14
--- flbind.cpp	11 Sep 2004 04:00:41 -0000	1.15
***************
*** 36,40 ****
          pxbnd_class = new t_class;
  
!         pxbnd_class->c_sym = gensym("");
          pxbnd_class->c_freelist = &px_freelist;
          pxbnd_class->c_freefun = NULL;
--- 36,40 ----
          pxbnd_class = new t_class;
  
!         pxbnd_class->c_sym = sym__;
          pxbnd_class->c_freelist = &px_freelist;
          pxbnd_class->c_freefun = NULL;
***************
*** 44,48 ****
          px_messlist[0].m_sym = (t_symbol *)pxbnd_class;
  
!         px_messlist[1].m_sym = gensym("anything");
          px_messlist[1].m_fun = (method)pxbnd_object::px_method;
          px_messlist[1].m_type[0] = A_GIMME;
--- 44,48 ----
          px_messlist[0].m_sym = (t_symbol *)pxbnd_class;
  
!         px_messlist[1].m_sym = sym_anything;
          px_messlist[1].m_fun = (method)pxbnd_object::px_method;
          px_messlist[1].m_type[0] = A_GIMME;

Index: flatom.cpp
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/flext/source/flatom.cpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** flatom.cpp	3 Aug 2003 02:36:45 -0000	1.9
--- flatom.cpp	11 Sep 2004 04:00:41 -0000	1.10
***************
*** 43,49 ****
  t_atom *flext::CopyList(int argc,const t_atom *argv)
  {
- 	int i;
  	t_atom *dst = new t_atom[argc];
! 	for(i = 0; i < argc; ++i) CopyAtom(dst+i,argv+i);
  	return dst;
  }
--- 43,48 ----
  t_atom *flext::CopyList(int argc,const t_atom *argv)
  {
  	t_atom *dst = new t_atom[argc];
!     memcpy(dst,argv,argc*sizeof(t_atom));
  	return dst;
  }

Index: flmeth.cpp
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/flext/source/flmeth.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** flmeth.cpp	21 Jun 2004 13:58:19 -0000	1.10
--- flmeth.cpp	11 Sep 2004 04:00:41 -0000	1.11
***************
*** 126,133 ****
  bool flext_base::ListMethods(int inlet) const
  {
      if(procattr) {
          AtomList la;
          ListMethods(la,inlet);
!         ToOutAnything(GetOutAttr(),MakeSymbol("methods"),la.Count(),la.Atoms());
          return true;
      }
--- 126,135 ----
  bool flext_base::ListMethods(int inlet) const
  {
+     static const t_symbol *sym_methods = MakeSymbol("methods");
+ 
      if(procattr) {
          AtomList la;
          ListMethods(la,inlet);
!         ToOutAnything(GetOutAttr(),sym_methods,la.Count(),la.Atoms());
          return true;
      }

Index: flclass.h
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/flext/source/flclass.h,v
retrieving revision 1.44
retrieving revision 1.45
diff -C2 -d -r1.44 -r1.45
*** flclass.h	23 Apr 2004 22:14:12 -0000	1.44
--- flclass.h	11 Sep 2004 04:00:41 -0000	1.45
***************
*** 277,287 ****
  
  	//! Send bang to self (inlet n)
! 	void ToSelfBang(int n) const; 
  
  	//! Send float to self (inlet n)
! 	void ToSelfFloat(int n,float f) const; 
  
  	//! Send integer to self (inlet n)
! 	void ToSelfInt(int n,int f) const; 
  
  	//! Send boolean to self (inlet n)
--- 277,287 ----
  
  	//! Send bang to self (inlet n)
!     void ToSelfBang(int n) const { ToQueueBang(-1-n); }
  
  	//! Send float to self (inlet n)
!     void ToSelfFloat(int n,float f) const { ToQueueFloat(-1-n,f); }
  
  	//! Send integer to self (inlet n)
!     void ToSelfInt(int n,int f) const { ToQueueInt(-1-n,f); }
  
  	//! Send boolean to self (inlet n)
***************
*** 289,303 ****
  
  	//! Send symbol to self (inlet n)
! 	void ToSelfSymbol(int n,const t_symbol *s) const; 
  	//! Send string aka symbol to self (inlet 0)
  	void ToSelfString(int n,const char *s) const { ToSelfSymbol(n,MakeSymbol(s)); }
  
  	//! Send list to self (inlet n)
! 	void ToSelfList(int n,int argc,const t_atom *argv) const; 
  	//! Send list to self (inlet n)
  	void ToSelfList(int n,const AtomList &list) const  { ToSelfList(n,list.Count(),list.Atoms()); }
  
  	//! Send anything to self (inlet n)
! 	void ToSelfAnything(int n,const t_symbol *s,int argc,const t_atom *argv)  const; 
  	//! Send anything to self (inlet n)
  	void ToSelfAnything(int n,const AtomAnything &any) const { ToSelfAnything(n,any.Header(),any.Count(),any.Atoms()); }
--- 289,303 ----
  
  	//! Send symbol to self (inlet n)
!     void ToSelfSymbol(int n,const t_symbol *s) const { ToQueueSymbol(-1-n,s); }
  	//! Send string aka symbol to self (inlet 0)
  	void ToSelfString(int n,const char *s) const { ToSelfSymbol(n,MakeSymbol(s)); }
  
  	//! Send list to self (inlet n)
!     void ToSelfList(int n,int argc,const t_atom *argv) const { ToQueueList(-1-n,argc,argv); }
  	//! Send list to self (inlet n)
  	void ToSelfList(int n,const AtomList &list) const  { ToSelfList(n,list.Count(),list.Atoms()); }
  
  	//! Send anything to self (inlet n)
!     void ToSelfAnything(int n,const t_symbol *s,int argc,const t_atom *argv) const { ToQueueAnything(-1-n,s,argc,argv); }
  	//! Send anything to self (inlet n)
  	void ToSelfAnything(int n,const AtomAnything &any) const { ToSelfAnything(n,any.Header(),any.Count(),any.Atoms()); }





More information about the Pd-cvs mailing list