diff options
Diffstat (limited to 'externals/grill/flext/source')
-rwxr-xr-x | externals/grill/flext/source/flqueue.cpp | 13 | ||||
-rw-r--r-- | externals/grill/flext/source/flsupport.h | 5 | ||||
-rw-r--r-- | externals/grill/flext/source/flthr.cpp | 28 |
3 files changed, 25 insertions, 21 deletions
diff --git a/externals/grill/flext/source/flqueue.cpp b/externals/grill/flext/source/flqueue.cpp index a9077230..a83aa01e 100755 --- a/externals/grill/flext/source/flqueue.cpp +++ b/externals/grill/flext/source/flqueue.cpp @@ -23,9 +23,11 @@ WARRANTIES, see the file, "license.txt," in this distribution. #ifdef FLEXT_THREADS //! Thread id of message queue thread -flext::thrid_t flext::thrmsgid = 0; +flext::thrid_t flext::thrmsgid; #endif +static bool qustarted = false; + #ifdef FLEXT_SHARED /* For the shared version it _should_ be possible to have only one queue for all externals. @@ -299,6 +301,7 @@ static void Trigger() void flext_base::QWorker(thr_params *) { thrmsgid = GetThreadId(); + qustarted = true; for(;;) { qthrcond.Wait(); QWork(true); @@ -308,19 +311,19 @@ void flext_base::QWorker(thr_params *) void flext_base::StartQueue() { - static bool started = false; - if(started) return; - else started = true; - + if(qustarted) return; #if FLEXT_QMODE == 1 #ifdef PERMANENTIDLE sys_callback(QTick,NULL,0); + qustarted = true; #endif #elif FLEXT_QMODE == 2 LaunchThread(QWorker,NULL); + while(!qustarted) Sleep(0.001); #elif FLEXT_QMODE == 0 && (FLEXT_SYS == FLEXT_SYS_PD || FLEXT_SYS == FLEXT_SYS_MAX) // qclk = (t_qelem *)(qelem_new(NULL,(t_method)QTick)); qclk = (t_clock *)(clock_new(NULL,(t_method)QTick)); + qustarted = true; #else #error Not implemented! #endif diff --git a/externals/grill/flext/source/flsupport.h b/externals/grill/flext/source/flsupport.h index da9a19ae..87e198f8 100644 --- a/externals/grill/flext/source/flsupport.h +++ b/externals/grill/flext/source/flsupport.h @@ -17,6 +17,7 @@ WARRANTIES, see the file, "license.txt," in this distribution. #include "flstdc.h" #include <new> +#include <string.h> /*! \defgroup FLEXT_SUPPORT Flext support classes @{ @@ -828,12 +829,14 @@ protected: static thrid_t thrhelpid; static thrid_t thrmsgid; - static bool StartHelper(); static void ThrHelper(void *); //! the system's thread id static thrid_t thrid; // the system thread +private: + static bool StartHelper(); // used in flext::Setup() + public: /*! \brief Yield to other threads diff --git a/externals/grill/flext/source/flthr.cpp b/externals/grill/flext/source/flthr.cpp index e7e534eb..8f2a5966 100644 --- a/externals/grill/flext/source/flthr.cpp +++ b/externals/grill/flext/source/flthr.cpp @@ -38,11 +38,11 @@ WARRANTIES, see the file, "license.txt," in this distribution. #include <errno.h> -//! Thread id of system thread -flext::thrid_t flext::thrid = 0; +//! Thread id of system thread - will be initialized in flext::Setup +flext::thrid_t flext::thrid; -//! Thread id of helper thread -flext::thrid_t flext::thrhelpid = 0; +//! Thread id of helper thread - will be initialized in flext::Setup +flext::thrid_t flext::thrhelpid; //! \brief This represents an entry to the list of active method threads @@ -110,30 +110,26 @@ static void LaunchHelper(thr_entry *e) e->meth(e->params); } +bool initialized = false; //! Start helper thread bool flext::StartHelper() { - if(thrhelpid) return true; - - if(!thrid) { - // system thread has not been set - ERRINTERNAL(); - return false; - } - bool ok = false; + initialized = false; #if FLEXT_THREADS == FLEXT_THR_POSIX pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_DETACHED); - ok = pthread_create (&thrhelpid,&attr,(void *(*)(void *))ThrHelper,NULL) == 0; + pthread_t tmp; + ok = pthread_create (&tmp,&attr,(void *(*)(void *))ThrHelper,NULL) == 0; #elif FLEXT_THREADS == FLEXT_THR_MP if(!MPLibraryIsLoaded()) error("Thread library is not loaded"); else { - OSStatus ret = MPCreateTask((TaskProc)ThrHelper,NULL,0,0,0,0,0,&thrhelpid); + MPTaskID tmp; + OSStatus ret = MPCreateTask((TaskProc)ThrHelper,NULL,0,0,0,0,0,&tmp); ok = ret == noErr; } #elif FLEXT_THREADS == FLEXT_THR_WIN32 @@ -145,7 +141,7 @@ bool flext::StartHelper() error("flext - Could not launch helper thread!"); else { // now we have to wait for thread helper to initialize - while(!thrhelpid || !thrhelpcond) Sleep(0.001); + while(!initialized) Sleep(0.001); // we are ready for threading now! } @@ -174,6 +170,8 @@ void flext::ThrHelper(void *) thrhelpcond = new ThrCond; + initialized = true; + // helper loop for(;;) { thrhelpcond->Wait(); |