From 3e90874e5d63137c195c3b3c1ce90b542deb8a51 Mon Sep 17 00:00:00 2001 From: Thomas Grill Date: Sun, 27 Feb 2005 04:56:10 +0000 Subject: small name change and reuse of Fifo cells fixed eol-style new lock-free lifo and fifo fixes for linux eliminated ChannelsIn/ChannelsOut updated docs build system: added profiler mode, more fixes fix for linux autodetection of build platform fix for flext_dsp @ Max svn path=/trunk/; revision=2584 --- externals/grill/flext/source/flcontainers.h | 46 +++++++++++++++++------ externals/grill/flext/source/flqueue.cpp | 57 ++++++++++++++++++----------- 2 files changed, 70 insertions(+), 33 deletions(-) (limited to 'externals/grill/flext/source') diff --git a/externals/grill/flext/source/flcontainers.h b/externals/grill/flext/source/flcontainers.h index 562bbf64..14d793de 100644 --- a/externals/grill/flext/source/flcontainers.h +++ b/externals/grill/flext/source/flcontainers.h @@ -21,15 +21,6 @@ WARRANTIES, see the file, "license.txt," in this distribution. #include "flprefix.h" -class Cell -{ - friend class Lifo; - friend class Fifo; -private: - Cell *link; -}; - - #if 1 //def __Pentium__ #define VTYPE volatile #else @@ -42,6 +33,14 @@ private: class FLEXT_SHARE Lifo { public: + class Cell + { + friend class Lifo; + friend class Fifo; + private: + Cell *link; + }; + inline Lifo() { Init(); } inline void Init() { ic = oc = 0; top = NULL; } @@ -113,7 +112,7 @@ public: } inline size_t Size() const { return ic-oc; } -#elif defined(__GNUC__) && defined(__) +#elif defined(__GNUC__) && (defined(_X86_) || defined(__i386__) || defined(__i586__) || defined(__i686__)) #ifndef SMPLOCK # ifdef __SMP__ # define SMPLOCK "lock ; " @@ -145,7 +144,7 @@ public: inline Cell *Pop() { - cell* v=0; + Cell *v=0; __asm__ __volatile__ ( "# LFPOP \n\t" "pushl %%ebx \n\t" @@ -171,7 +170,7 @@ public: return v; } - inline size_t Size() + inline size_t Size() const { size_t n; __asm__ __volatile__ ( @@ -258,10 +257,22 @@ private: #endif }; +template +class TypedLifo + : public Lifo +{ +public: + inline T *Avail() { return static_cast(Lifo::Avail()); } + inline void Push(T *c) { Lifo::Push(static_cast(c)); } + inline T *Pop() { return static_cast(Lifo::Pop()); } +}; + class FLEXT_SHARE Fifo { public: + typedef Lifo::Cell Cell; + void Init() { in.Init(); out.Init(); } inline size_t Size() const { return in.Size()+out.Size(); } @@ -311,5 +322,16 @@ public: Lifo in,out; }; +template +class TypedFifo + : public Fifo +{ +public: + inline T *Avail() { return static_cast(Fifo::Avail()); } + inline void Put(T *c) { Fifo::Put(static_cast(c)); } + inline T *Get() { return static_cast(Fifo::Get()); } + inline T *Clear() { return static_cast(Fifo::Clear()); } +}; + #endif diff --git a/externals/grill/flext/source/flqueue.cpp b/externals/grill/flext/source/flqueue.cpp index 62a8b35a..75f7842e 100755 --- a/externals/grill/flext/source/flqueue.cpp +++ b/externals/grill/flext/source/flqueue.cpp @@ -29,7 +29,7 @@ flext::thrid_t flext::thrmsgid = 0; class qmsg: public flext, - public Cell + public Fifo::Cell { public: qmsg(flext_base *t,int o,const t_symbol *s,int ac,const t_atom *av) @@ -37,6 +37,13 @@ public: , th(t),out(o) {} + void Set(flext_base *t,int o,const t_symbol *s,int ac,const t_atom *av) + { + th = t; + out = o; + msg(s,ac,av); + } + // \note PD sys lock must already be held by caller void Send() const { @@ -59,28 +66,26 @@ private: */ class Queue: public flext, - public Fifo + public TypedFifo { public: inline bool Empty() const { return Size() == 0; } - inline void Push(qmsg *q) { Fifo::Put(q); } - - inline qmsg *Pop() { return static_cast(Fifo::Get()); } + void New(flext_base *t,int o,const t_symbol *s,int ac,const t_atom *av); - void Push(flext_base *th,int o) // bang + inline void Push(flext_base *th,int o) // bang { - Put(new qmsg(th,o,sym_bang,0,NULL)); + New(th,o,sym_bang,0,NULL); } - void Push(flext_base *th,int o,float dt) + inline void Push(flext_base *th,int o,float dt) { t_atom at; SetFloat(at,dt); - Put(new qmsg(th,o,sym_float,1,&at)); + New(th,o,sym_float,1,&at); } - void Push(flext_base *th,int o,int dt) + inline void Push(flext_base *th,int o,int dt) { t_atom at; SetInt(at,dt); @@ -92,14 +97,14 @@ public: #else #error Not implemented! #endif - Put(new qmsg(th,o,sym,1,&at)); + New(th,o,sym,1,&at); } - void Push(flext_base *th,int o,const t_symbol *dt) + inline void Push(flext_base *th,int o,const t_symbol *dt) { t_atom at; SetSymbol(at,dt); - Put(new qmsg(th,o,sym_symbol,1,&at)); + New(th,o,sym_symbol,1,&at); } void Push(flext_base *th,int o,const t_atom &a) @@ -121,21 +126,31 @@ public: error("atom type not supported"); return; } - Put(new qmsg(th,o,sym,1,&a)); + New(th,o,sym,1,&a); } - void Push(flext_base *th,int o,int argc,const t_atom *argv) + inline void Push(flext_base *th,int o,int argc,const t_atom *argv) { - Put(new qmsg(th,o,sym_list,argc,argv)); + New(th,o,sym_list,argc,argv); } - void Push(flext_base *th,int o,const t_symbol *sym,int argc,const t_atom *argv) + inline void Push(flext_base *th,int o,const t_symbol *sym,int argc,const t_atom *argv) { - Put(new qmsg(th,o,sym,argc,argv)); + New(th,o,sym,argc,argv); } }; -static Queue queue; +static Queue queue,requeue; + +void Queue::New(flext_base *t,int o,const t_symbol *s,int ac,const t_atom *av) +{ + qmsg *m = requeue.Get(); + if(m) + m->Set(t,o,s,ac,av); + else + m = new qmsg(t,o,s,ac,av); + Put(m); +} #if FLEXT_QMODE == 2 @@ -163,9 +178,9 @@ static void QWork(bool syslock) #endif qmsg *q; - while((q = queue.Pop()) != NULL) { + while((q = queue.Get()) != NULL) { q->Send(); - delete q; + requeue.Put(q); } #if FLEXT_QMODE == 2 -- cgit v1.2.1