diff options
author | Thomas Grill <xovo@users.sourceforge.net> | 2003-12-27 03:32:55 +0000 |
---|---|---|
committer | Thomas Grill <xovo@users.sourceforge.net> | 2003-12-27 03:32:55 +0000 |
commit | b58a4e32bd6a69b21e32651128d0223fa185d3e7 (patch) | |
tree | b0b7a5dfa7494e029ad5bad6dca15a5652acd924 /externals/grill/flext/source | |
parent | d10ebb2a7ad78029474186b7e610fe1611d3bcd8 (diff) |
""
svn path=/trunk/; revision=1231
Diffstat (limited to 'externals/grill/flext/source')
-rw-r--r-- | externals/grill/flext/source/flext.h | 4 | ||||
-rw-r--r-- | externals/grill/flext/source/flsupport.cpp | 41 | ||||
-rw-r--r-- | externals/grill/flext/source/flsupport.h | 35 | ||||
-rw-r--r-- | externals/grill/flext/source/flthr.cpp | 36 |
4 files changed, 114 insertions, 2 deletions
diff --git a/externals/grill/flext/source/flext.h b/externals/grill/flext/source/flext.h index 47f15ec1..2ce48d5a 100644 --- a/externals/grill/flext/source/flext.h +++ b/externals/grill/flext/source/flext.h @@ -23,10 +23,10 @@ WARRANTIES, see the file, "license.txt," in this distribution. */ //! \brief flext version number -#define FLEXT_VERSION 405 +#define FLEXT_VERSION 406 //! \brief flext version string -#define FLEXT_VERSTR "0.4.5" +#define FLEXT_VERSTR "0.4.6pre" //! @} diff --git a/externals/grill/flext/source/flsupport.cpp b/externals/grill/flext/source/flsupport.cpp index db2b1770..d8bddd42 100644 --- a/externals/grill/flext/source/flsupport.cpp +++ b/externals/grill/flext/source/flsupport.cpp @@ -35,6 +35,7 @@ const t_symbol *flext::sym_signal = NULL; int flext::Version() { return FLEXT_VERSION; } const char *flext::VersionStr() { return FLEXT_VERSTR; } + void flext::Setup() { static bool issetup = false; @@ -68,6 +69,46 @@ void flext::Setup() #endif #ifdef FLEXT_THREADS + +#if FLEXT_SYS == FLEXT_SYS_MAX && FLEXT_OS == FLEXT_OS_MAC && FLEXT_THREADS == FLEXT_THR_POSIX + // for Max OSX/CFM MachO functions have to be imported + CFBundleRef bundle = NULL; + if (bundle = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.Carbon"))) + { + //load pthread function pointers + pthread_self = CFBundleGetFunctionPointerForName(bundle, CFSTR("pthread_self")); + pthread_equal = CFBundleGetFunctionPointerForName(bundle, CFSTR("pthread_equal")); + pthread_create = CFBundleGetFunctionPointerForName(bundle, CFSTR("pthread_create")); + pthread_cancel = CFBundleGetFunctionPointerForName(bundle, CFSTR("pthread_cancel")); + pthread_testcancel = CFBundleGetFunctionPointerForName(bundle, CFSTR("pthread_testcancel")); + pthread_join = CFBundleGetFunctionPointerForName(bundle, CFSTR("pthread_join")); + pthread_exit = CFBundleGetFunctionPointerForName(bundle, CFSTR("pthread_exit")); + + pthread_attr_init = CFBundleGetFunctionPointerForName(bundle, CFSTR("pthread_attr_init")); + pthread_attr_destroy = CFBundleGetFunctionPointerForName(bundle, CFSTR("pthread_attr_destroy")); + pthread_attr_setdetachstate = CFBundleGetFunctionPointerForName(bundle, CFSTR("pthread_attr_setdetachstate")); + + pthread_attr_getschedparam = CFBundleGetFunctionPointerForName(bundle, CFSTR("pthread_attr_getschedparam")); + pthread_attr_setschedparam = CFBundleGetFunctionPointerForName(bundle, CFSTR("pthread_attr_setschedparam")); + + pthread_mutex_init = CFBundleGetFunctionPointerForName(bundle, CFSTR("pthread_mutex_init")); + pthread_mutex_destroy = CFBundleGetFunctionPointerForName(bundle, CFSTR("pthread_mutex_destroy")); + pthread_mutex_lock = CFBundleGetFunctionPointerForName(bundle, CFSTR("pthread_mutex_lock")); + pthread_mutex_unlock = CFBundleGetFunctionPointerForName(bundle, CFSTR("pthread_mutex_unlock")); + pthread_mutex_trylock = CFBundleGetFunctionPointerForName(bundle, CFSTR("pthread_mutex_trylock")); + + pthread_cond_init = CFBundleGetFunctionPointerForName(bundle, CFSTR("pthread_cond_init")); + pthread_cond_destroy = CFBundleGetFunctionPointerForName(bundle, CFSTR("pthread_cond_destroy")); + pthread_cond_signal = CFBundleGetFunctionPointerForName(bundle, CFSTR("pthread_cond_signal")); + pthread_cond_wait = CFBundleGetFunctionPointerForName(bundle, CFSTR("pthread_cond_wait")); + pthread_cond_timedwait = CFBundleGetFunctionPointerForName(bundle, CFSTR("pthread_cond_timedwait")); + + sched_yield = CFBundleGetFunctionPointerForName(bundle, CFSTR("sched_yield")); + sched_get_priority_min = CFBundleGetFunctionPointerForName(bundle, CFSTR("sched_get_priority_min")); + sched_get_priority_max = CFBundleGetFunctionPointerForName(bundle, CFSTR("sched_get_priority_max")); + } +#endif + thrid = GetThreadId(); StartHelper(); #endif diff --git a/externals/grill/flext/source/flsupport.h b/externals/grill/flext/source/flsupport.h index c964c66e..3e2b6acd 100644 --- a/externals/grill/flext/source/flsupport.h +++ b/externals/grill/flext/source/flsupport.h @@ -649,6 +649,41 @@ public: @{ */ +#if FLEXT_SYS == FLEXT_SYS_MAX && FLEXT_OS == FLEXT_OS_MAC && FLEXT_THREADS == FLEXT_THR_POSIX + // These are function pointers of MachO functions imported to the CFM world + + static pthread_t (*pthread_self)(); + static int (*pthread_equal)(pthread_t,pthread_t); + static int (*pthread_create)(pthread_t *,const pthread_attr_t *,void *(*)(void *),void *); + static int (*pthread_cancel)(pthread_t); + static void (*pthread_testcancel)(void); + static int (*pthread_join)(pthread_t,void **); + static void (*pthread_exit)(void *); + + static int (*pthread_attr_init)(pthread_attr_t *); + static int (*pthread_attr_destroy)(pthread_attr_t *); + static int (*pthread_attr_setdetachstate)(pthread_attr_t *,int); + + static int (*pthread_getschedparam)(pthread_t,int *,struct sched_param *); + static int (*pthread_setschedparam)(pthread_t,int,const struct sched_param *); + + static int (*pthread_mutex_init)(pthread_mutex_t *,const pthread_mutexattr_t *); + static int (*pthread_mutex_destroy)(pthread_mutex_t *); + static int (*pthread_mutex_lock)(pthread_mutex_t *); + static int (*pthread_mutex_unlock)(pthread_mutex_t *); + static int (*pthread_mutex_trylock)(pthread_mutex_t *); + + static int (*pthread_cond_init)(pthread_cond_t *,const pthread_condattr_t *); + static int (*pthread_cond_destroy)(pthread_cond_t *); + static int (*pthread_cond_signal)(pthread_cond_t *); + static int (*pthread_cond_wait)(pthread_cond_t *,pthread_mutex_t *); + static int (*pthread_cond_timedwait)(pthread_cond_t *,pthread_mutex_t *,const struct timespec *); + + static int (*sched_yield)(void); + static int (*sched_get_priority_min)(int); + static int (*sched_get_priority_max)(int); +#endif + //! thread type #if FLEXT_THREADS == FLEXT_THR_MP typedef MPTaskID thrid_t; diff --git a/externals/grill/flext/source/flthr.cpp b/externals/grill/flext/source/flthr.cpp index 082fd161..f16ba76d 100644 --- a/externals/grill/flext/source/flthr.cpp +++ b/externals/grill/flext/source/flthr.cpp @@ -50,6 +50,29 @@ static bool thrhelpexit = false; static flext::ThrCond *thrhelpcond = NULL; +#if defined(FLEXT_THREADS) && FLEXT_SYS == FLEXT_SYS_MAX && FLEXT_OS == FLEXT_OS_MAC && FLEXT_THREADS == FLEXT_THR_POSIX +// utility code taken from from Apple's CFM_MachO_CFM example: +// +// This function allocates a block of CFM glue code which contains the instructions to call CFM routines +// +(void (*)(void *))MachOFunctionPointerForCFMFunctionPointer( (void (*)(void *))cfmfp ) +{ + // Apple utility code for CFM callback glue + static const UInt32 tmpl[6] = {0x3D800000, 0x618C0000, 0x800C0000, 0x804C0004, 0x7C0903A6, 0x4E800420}; + UInt32 *mfp = (UInt32*) NewPtr( sizeof(tmpl) ); // Must later dispose of allocated memory + // (this is freed with app heap in this object) + mfp[0] = tmpl[0] | ((UInt32)cfmfp >> 16); + mfp[1] = tmpl[1] | ((UInt32)cfmfp & 0xFFFF); + mfp[2] = tmpl[2]; + mfp[3] = tmpl[3]; + mfp[4] = tmpl[4]; + mfp[5] = tmpl[5]; + MakeDataExecutable( mfp, sizeof(tmpl) ); + return (void (*)(void *))mfp; +} +#endif + + flext::thrid_t flext::GetSysThreadId() { return thrid; } @@ -77,7 +100,12 @@ bool flext::StartHelper() pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_DETACHED); thrhelpexit = false; +#if FLEXT_SYS == FLEXT_SYS_MAX && FLEXT_OS == FLEXT_OS_MAC + void (*CFMThrHelper)(void *) = MachOFunctionPointerForCFMFunctionPointer(ThrHelper); + int ret = pthread_create (&thrhelpid,&attr,(void *(*)(void *))CFMThrHelper,NULL); +#else int ret = pthread_create (&thrhelpid,&attr,(void *(*)(void *))ThrHelper,NULL); +#endif ok = !ret; #elif FLEXT_THREADS == FLEXT_THR_MP if(!MPLibraryIsLoaded()) @@ -99,6 +127,10 @@ bool flext::StartHelper() // we are ready for threading now! } + +#if FLEXT_THREADS == FLEXT_THR_POSIX + pthread_attr_destroy(&attr); +#endif return ok; } @@ -190,6 +222,10 @@ void flext::ThrHelper(void *) delete thrhelpcond; thrhelpcond = NULL; + +#if FLEXT_THREADS == FLEXT_THR_POSIX + pthread_attr_destroy(&attr); +#endif } |