Update of /cvsroot/pure-data/externals/grill/flext/source
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7399/source
Modified Files:
flcontainers.h flqueue.cpp
Log Message:
updated flext lock-free containers
install flcontainers.h
Lifos and Fifos with reservoir
forgot about void...
Index: flqueue.cpp
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/flext/source/flqueue.cpp,v
retrieving revision 1.29
retrieving revision 1.30
diff -C2 -d -r1.29 -r1.30
*** flqueue.cpp 27 Feb 2005 04:56:10 -0000 1.29
--- flqueue.cpp 8 Mar 2005 04:57:17 -0000 1.30
***************
*** 28,31 ****
--- 28,33 ----
+ static void Trigger();
+
class qmsg:
public flext,
***************
*** 33,50 ****
{
public:
! qmsg(flext_base *t,int o,const t_symbol *s,int ac,const t_atom *av)
! : msg(s,ac,av)
! , 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
{
if(out < 0)
--- 35,48 ----
{
public:
! inline qmsg &Set(flext_base *t,int o,const t_symbol *s,int ac,const t_atom *av)
{
th = t;
out = o;
msg(s,ac,av);
+ return *this;
}
// \note PD sys lock must already be held by caller
! inline void Send() const
{
if(out < 0)
***************
*** 62,80 ****
};
! /* \TODO This is only thread-safe if called from one thread which need NOT be the case.
! Reimplement in a thread-safe manner!!!
! */
class Queue:
public flext,
! public TypedFifo<qmsg>
{
public:
inline bool Empty() const { return Size() == 0; }
! void New(flext_base *t,int o,const t_symbol *s,int ac,const t_atom *av);
inline void Push(flext_base *th,int o) // bang
{
! New(th,o,sym_bang,0,NULL);
}
--- 60,86 ----
};
!
!
! typedef PooledFifo<qmsg> QueueFifo;
!
class Queue:
public flext,
! public QueueFifo
{
public:
inline bool Empty() const { return Size() == 0; }
! inline void Push(flext_base *t,int o,const t_symbol *s,int ac,const t_atom *av)
! {
! qmsg *m = QueueFifo::New();
! FLEXT_ASSERT(m);
! m->Set(t,o,s,ac,av);
! Put(m);
! Trigger();
! }
inline void Push(flext_base *th,int o) // bang
{
! Push(th,o,sym_bang,0,NULL);
}
***************
*** 83,87 ****
t_atom at;
SetFloat(at,dt);
! New(th,o,sym_float,1,&at);
}
--- 89,93 ----
t_atom at;
SetFloat(at,dt);
! Push(th,o,sym_float,1,&at);
}
***************
*** 98,102 ****
#error Not implemented!
#endif
! New(th,o,sym,1,&at);
}
--- 104,108 ----
#error Not implemented!
#endif
! Push(th,o,sym,1,&at);
}
***************
*** 105,109 ****
t_atom at;
SetSymbol(at,dt);
! New(th,o,sym_symbol,1,&at);
}
--- 111,115 ----
t_atom at;
SetSymbol(at,dt);
! Push(th,o,sym_symbol,1,&at);
}
***************
*** 127,155 ****
return;
}
! New(th,o,sym,1,&a);
}
inline void Push(flext_base *th,int o,int argc,const t_atom *argv)
{
! New(th,o,sym_list,argc,argv);
! }
!
! inline void Push(flext_base *th,int o,const t_symbol *sym,int argc,const t_atom *argv)
! {
! New(th,o,sym,argc,argv);
}
};
! 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);
! }
--- 133,146 ----
return;
}
! Push(th,o,sym,1,&a);
}
inline void Push(flext_base *th,int o,int argc,const t_atom *argv)
{
! Push(th,o,sym_list,argc,argv);
}
};
! static Queue queue;
***************
*** 181,185 ****
while((q = queue.Get()) != NULL) {
q->Send();
! requeue.Put(q);
}
--- 172,176 ----
while((q = queue.Get()) != NULL) {
q->Send();
! queue.Free(q);
}
***************
*** 306,310 ****
{
queue.Push(const_cast<flext_base *>(this),o);
- Trigger();
}
--- 297,300 ----
***************
*** 312,316 ****
{
queue.Push(const_cast<flext_base *>(this),o,f);
- Trigger();
}
--- 302,305 ----
***************
*** 318,322 ****
{
queue.Push(const_cast<flext_base *>(this),o,f);
- Trigger();
}
--- 307,310 ----
***************
*** 324,328 ****
{
queue.Push(const_cast<flext_base *>(this),o,s);
- Trigger();
}
--- 312,315 ----
***************
*** 330,334 ****
{
queue.Push(const_cast<flext_base *>(this),o,at);
- Trigger();
}
--- 317,320 ----
***************
*** 336,340 ****
{
queue.Push(const_cast<flext_base *>(this),o,argc,argv);
- Trigger();
}
--- 322,325 ----
***************
*** 342,345 ****
{
queue.Push(const_cast<flext_base *>(this),o,s,argc,argv);
- Trigger();
}
--- 327,329 ----
Index: flcontainers.h
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/flext/source/flcontainers.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** flcontainers.h 6 Mar 2005 04:56:00 -0000 1.3
--- flcontainers.h 8 Mar 2005 04:57:01 -0000 1.4
***************
*** 271,275 ****
};
! template <typename T>
class PooledLifo
: public TypedLifo<T>
--- 271,275 ----
};
! template <typename T,int M = 2,int O = 1>
class PooledLifo
: public TypedLifo<T>
***************
*** 277,281 ****
public:
inline T *New() { T *n = reuse.Pop(); return n?n:new T; }
! inline Free(T *p) { if(reuse.Size() < Size()) reuse.Push(p); else delete p; }
private:
TypedLifo<T> reuse;
--- 277,282 ----
public:
inline T *New() { T *n = reuse.Pop(); return n?n:new T; }
! inline size_t Size() const { return TypedLifo<T>::Size(); }
! inline void Free(T *p) { if(reuse.Size() < Size()*M+O) reuse.Push(p); else delete p; }
private:
TypedLifo<T> reuse;
***************
*** 348,352 ****
};
! template <typename T>
class PooledFifo
: public TypedFifo<T>
--- 349,353 ----
};
! template <typename T,int M = 2,int O = 1>
class PooledFifo
: public TypedFifo<T>
***************
*** 354,358 ****
public:
inline T *New() { T *n = reuse.Pop(); return n?n:new T; }
! inline Free(T *p) { if(reuse.Size() < Size()) reuse.Push(p); else delete p; }
private:
TypedLifo<T> reuse;
--- 355,360 ----
public:
inline T *New() { T *n = reuse.Pop(); return n?n:new T; }
! inline size_t Size() const { return TypedFifo<T>::Size(); }
! inline void Free(T *p) { if(reuse.Size() < Size()*M+O) reuse.Push(p); else delete p; }
private:
TypedLifo<T> reuse;