From f81282808b0d9147fc0c980e418c56774d1f6735 Mon Sep 17 00:00:00 2001 From: Thomas Grill Date: Sat, 14 Jun 2003 02:32:39 +0000 Subject: "" svn path=/trunk/; revision=702 --- externals/grill/flext/changes.txt | 1 + externals/grill/flext/flext.vcproj | 651 ++++++++++++++++++++++++++++++- externals/grill/flext/makefile.pd-linux | 6 +- externals/grill/flext/source/flclass.h | 31 +- externals/grill/flext/source/flext.cpp | 19 +- externals/grill/flext/source/flprefix.h | 17 +- externals/grill/flext/source/flqueue.cpp | 178 ++++++--- externals/grill/flext/source/flthr.cpp | 3 - 8 files changed, 815 insertions(+), 91 deletions(-) (limited to 'externals/grill/flext') diff --git a/externals/grill/flext/changes.txt b/externals/grill/flext/changes.txt index 696f4266..181c50c1 100644 --- a/externals/grill/flext/changes.txt +++ b/externals/grill/flext/changes.txt @@ -17,6 +17,7 @@ Version history: - added some more SIMD functions - fixed wrong returned result of flext::buffer::set function - fix for linux static exported function name-clash (flext::Setup() single- vs. multi-threading) +- made message queue stuff global (static) for all flext objects 0.4.4: - fixed deadly bug for Max/MSP method-to-symbol-binding proxies diff --git a/externals/grill/flext/flext.vcproj b/externals/grill/flext/flext.vcproj index dc1a82c6..f49d92ae 100644 --- a/externals/grill/flext/flext.vcproj +++ b/externals/grill/flext/flext.vcproj @@ -336,6 +336,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -415,6 +532,26 @@ AdditionalIncludeDirectories="" PreprocessorDefinitions=""/> + + + + + + @@ -472,6 +609,26 @@ AdditionalIncludeDirectories="" PreprocessorDefinitions=""/> + + + + + + @@ -529,6 +686,26 @@ AdditionalIncludeDirectories="" PreprocessorDefinitions=""/> + + + + + + @@ -586,6 +763,26 @@ AdditionalIncludeDirectories="" PreprocessorDefinitions=""/> + + + + + + + + + + + + @@ -710,6 +927,26 @@ AdditionalIncludeDirectories="" PreprocessorDefinitions=""/> + + + + + + @@ -773,6 +1010,26 @@ AdditionalIncludeDirectories="" PreprocessorDefinitions=""/> + + + + + + @@ -836,6 +1093,26 @@ AdditionalIncludeDirectories="" PreprocessorDefinitions=""/> + + + + + + + + + + + + @@ -954,6 +1251,26 @@ AdditionalIncludeDirectories="" PreprocessorDefinitions=""/> + + + + + + @@ -1011,6 +1328,26 @@ AdditionalIncludeDirectories="" PreprocessorDefinitions=""/> + + + + + + @@ -1061,12 +1398,32 @@ PreprocessorDefinitions=""/> + Name="Release|Win32"> + + + + + + + PreprocessorDefinitions="" + BasicRuntimeChecks="3" + BrowseInformation="1"/> + + + + + + @@ -1182,6 +1559,26 @@ AdditionalIncludeDirectories="" PreprocessorDefinitions=""/> + + + + + + @@ -1239,6 +1636,26 @@ AdditionalIncludeDirectories="" PreprocessorDefinitions=""/> + + + + + + @@ -1296,6 +1713,26 @@ AdditionalIncludeDirectories="" PreprocessorDefinitions=""/> + + + + + + @@ -1353,6 +1790,26 @@ AdditionalIncludeDirectories="" PreprocessorDefinitions=""/> + + + + + + + + + + + + @@ -1474,6 +1951,26 @@ AdditionalIncludeDirectories="" PreprocessorDefinitions=""/> + + + + + + @@ -1531,6 +2028,26 @@ AdditionalIncludeDirectories="" PreprocessorDefinitions=""/> + + + + + + @@ -1591,6 +2108,26 @@ AdditionalIncludeDirectories="" PreprocessorDefinitions=""/> + + + + + + @@ -1648,6 +2185,26 @@ AdditionalIncludeDirectories="" PreprocessorDefinitions=""/> + + + + + + + + + + + + @@ -1773,9 +2350,43 @@ AdditionalIncludeDirectories="" PreprocessorDefinitions=""/> + + + + + + + + + + + + + + + + + + + + + + + + IsSystemThread()) { - error("flext - Queue tick called by wrong thread!"); - return; - } + +#ifdef FLEXT_THREADS +static flext::ThrMutex qmutex; #endif +static void QWork(bool qlock,bool syslock) +{ #ifdef FLEXT_THREADS - th->qmutex.Lock(); + if(qlock) qmutex.Lock(); #endif -#ifdef FLEXT_PDLOCK - pd_lock(); +#ifdef FLEXT_QTHR + if(syslock) pd_lock(); #endif + for(;;) { - qmsg *m = th->qhead; + qmsg *m = qhead; if(!m) break; if(m->out < 0) { @@ -94,30 +94,30 @@ void flext_base::QTick(flext_base *th) switch(m->tp) { case qmsg::tp_bang: - th->m_methodmain(n,sym_bang,0,&tmp); + m->th->m_methodmain(n,flext::sym_bang,0,&tmp); break; case qmsg::tp_float: - SetFloat(tmp,m->_float); - th->m_methodmain(n,sym_float,1,&tmp); + flext::SetFloat(tmp,m->_float); + m->th->m_methodmain(n,flext::sym_float,1,&tmp); break; case qmsg::tp_int: - SetInt(tmp,m->_int); + flext::SetInt(tmp,m->_int); #if FLEXT_SYS == FLEXT_SYS_PD - th->m_methodmain(n,sym_float,1,&tmp); + m->th->m_methodmain(n,flext::sym_float,1,&tmp); #elif FLEXT_SYS == FLEXT_SYS_MAX - th->m_methodmain(n,sym_int,1,&tmp); + m->th->m_methodmain(n,flext::sym_int,1,&tmp); #else #error Not implemented! #endif case qmsg::tp_sym: - SetSymbol(tmp,m->_sym); - th->m_methodmain(n,sym_symbol,1,&tmp); + flext::SetSymbol(tmp,m->_sym); + m->th->m_methodmain(n,flext::sym_symbol,1,&tmp); break; case qmsg::tp_list: - th->m_methodmain(n,sym_list,m->_list.argc,m->_list.argv); + m->th->m_methodmain(n,flext::sym_list,m->_list.argc,m->_list.argv); break; case qmsg::tp_any: - th->m_methodmain(n,m->_any.s,m->_any.argc,m->_any.argv); + m->th->m_methodmain(n,m->_any.s,m->_any.argc,m->_any.argv); break; #ifdef FLEXT_DEBUG default: ERRINTERNAL(); @@ -128,32 +128,64 @@ void flext_base::QTick(flext_base *th) // message to outlet switch(m->tp) { - case qmsg::tp_bang: th->ToOutBang(m->out); break; - case qmsg::tp_float: th->ToOutFloat(m->out,m->_float); break; - case qmsg::tp_int: th->ToOutInt(m->out,m->_int); break; - case qmsg::tp_sym: th->ToOutSymbol(m->out,m->_sym); break; - case qmsg::tp_list: th->ToOutList(m->out,m->_list.argc,m->_list.argv); break; - case qmsg::tp_any: th->ToOutAnything(m->out,m->_any.s,m->_any.argc,m->_any.argv); break; + case qmsg::tp_bang: m->th->ToOutBang(m->out); break; + case qmsg::tp_float: m->th->ToOutFloat(m->out,m->_float); break; + case qmsg::tp_int: m->th->ToOutInt(m->out,m->_int); break; + case qmsg::tp_sym: m->th->ToOutSymbol(m->out,m->_sym); break; + case qmsg::tp_list: m->th->ToOutList(m->out,m->_list.argc,m->_list.argv); break; + case qmsg::tp_any: m->th->ToOutAnything(m->out,m->_any.s,m->_any.argc,m->_any.argv); break; #ifdef FLEXT_DEBUG default: ERRINTERNAL(); #endif } } - th->qhead = m->nxt; - if(!th->qhead) th->qtail = NULL; + qhead = m->nxt; + if(!qhead) qtail = NULL; m->nxt = NULL; delete m; } -#ifdef FLEXT_PDLOCK - pd_unlock(); +#ifdef FLEXT_QTHR + if(syslock) pd_unlock(); +#endif +#ifdef FLEXT_THREADS + if(qlock) qmutex.Unlock(); +#endif +} + +#if FLEXT_SYS == FLEXT_SYS_JMAX +static void QTick(fts_object_t *c,int winlet, fts_symbol_t s, int ac, const fts_atom_t *at) +{ +#else +static void QTick(flext_base *c) +{ +#endif +// post("qtick"); +#if defined(FLEXT_THREADS) && defined(FLEXT_DEBUG) && !defined(FLEXT_QTHR) + if(!flext::IsSystemThread()) { + error("flext - Queue tick called by wrong thread!"); + return; + } #endif + QWork(true,true); +} + +/* +It would be sufficient to only flush messages belonging to object th +But then the order of sent messages is not as intended +*/ +void flext_base::QFlush(flext_base *th) +{ #ifdef FLEXT_THREADS - th->qmutex.Unlock(); + if(!IsSystemThread()) { + error("flext - Queue flush called by wrong thread!"); + return; + } #endif + while(qhead) QWork(true,false); } -void flext_base::Queue(qmsg *m) +static void Queue(qmsg *m) { // post("Queue"); @@ -168,11 +200,11 @@ void flext_base::Queue(qmsg *m) #endif #if FLEXT_SYS == FLEXT_SYS_PD - #ifdef FLEXT_PDLOCK + #ifdef FLEXT_QTHR // wake up a worker thread // (instead of triggering the clock) - clock_delay(qclk,0); - #else + qthrcond.Signal(); + #else clock_delay(qclk,0); #endif #elif FLEXT_SYS == FLEXT_SYS_MAX @@ -181,50 +213,76 @@ void flext_base::Queue(qmsg *m) // this is dangerous because there may be other timers on this object! fts_timebase_add_call(fts_get_timebase(), (fts_object_t *)thisHdr(), QTick, NULL, 0); #else -#error +#error Not implemented +#endif +} + +#ifdef FLEXT_QTHR +void QWorker(flext::thr_params *) +{ + for(;;) { + qthrcond.Wait(); + QWork(true,true); + } +} +#endif + +void flext_base::StartQueue() +{ + // message queue ticker + qhead = qtail = NULL; + +#ifdef FLEXT_QTHR + LaunchThread(QWorker,NULL); +#else +#if FLEXT_SYS == FLEXT_SYS_PD || FLEXT_SYS == FLEXT_SYS_MAX + qclk = (t_qelem *)(qelem_new(NULL,(t_method)QTick)); +#else +#error Not implemented! +#endif #endif } void flext_base::ToQueueBang(int o) const { - qmsg *m = new qmsg(); + qmsg *m = new qmsg(const_cast(this)); m->SetBang(o); - const_cast(*this).Queue(m); + Queue(m); } void flext_base::ToQueueFloat(int o,float f) const { - qmsg *m = new qmsg; + qmsg *m = new qmsg(const_cast(this)); m->SetFloat(o,f); - const_cast(*this).Queue(m); + Queue(m); } void flext_base::ToQueueInt(int o,int f) const { - qmsg *m = new qmsg; + qmsg *m = new qmsg(const_cast(this)); m->SetInt(o,f); - const_cast(*this).Queue(m); + Queue(m); } void flext_base::ToQueueSymbol(int o,const t_symbol *s) const { - qmsg *m = new qmsg; + qmsg *m = new qmsg(const_cast(this)); m->SetSymbol(o,s); - const_cast(*this).Queue(m); + Queue(m); } void flext_base::ToQueueList(int o,int argc,const t_atom *argv) const { - qmsg *m = new qmsg; + qmsg *m = new qmsg(const_cast(this)); m->SetList(o,argc,argv); - const_cast(*this).Queue(m); + Queue(m); } void flext_base::ToQueueAnything(int o,const t_symbol *s,int argc,const t_atom *argv) const { - qmsg *m = new qmsg; + qmsg *m = new qmsg(const_cast(this)); m->SetAny(o,s,argc,argv); - const_cast(*this).Queue(m); + Queue(m); } diff --git a/externals/grill/flext/source/flthr.cpp b/externals/grill/flext/source/flthr.cpp index 5c4a31c8..3bd5bbf4 100644 --- a/externals/grill/flext/source/flthr.cpp +++ b/externals/grill/flext/source/flthr.cpp @@ -283,8 +283,6 @@ bool flext_base::StopThreads() #endif // --- all object threads have terminated by now ------- - - qmutex.Lock(); // Lock message queue tlmutex.Lock(); // timeout -> hard termination @@ -306,7 +304,6 @@ bool flext_base::StopThreads() thrhead = NULL; tlmutex.Unlock(); - qmutex.Unlock(); } // post("All threads have terminated"); -- cgit v1.2.1