diff --git a/ChangeLog b/ChangeLog index c4d406d4..25ba5dd8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -24,6 +24,10 @@ Torben Hohn Jackdmp changes log --------------------------- +2009-03-12 Stephane Letz + + * Virtualize and allow overriding of thread creation function, to allow Wine support (from JACK1). + 2009-03-12 Stephane Letz * Try automatic adaptative mode in adapters. diff --git a/common/JackAPI.cpp b/common/JackAPI.cpp index 02b8ff8d..262135b1 100644 --- a/common/JackAPI.cpp +++ b/common/JackAPI.cpp @@ -222,6 +222,7 @@ extern "C" EXPORT int jack_client_stop_thread (jack_client_t* client, pthread_t thread); EXPORT int jack_client_kill_thread (jack_client_t* client, pthread_t thread); + EXPORT void jack_set_thread_creator (jack_thread_creator_t jtc); EXPORT char * jack_get_internal_client_name (jack_client_t *client, jack_intclient_t intclient); @@ -1792,6 +1793,11 @@ EXPORT int jack_client_kill_thread(jack_client_t* client, pthread_t thread) return JackThread::KillImp(thread); } +EXPORT void jack_set_thread_creator (jack_thread_creator_t jtc) +{ + JackGlobals::fJackThreadCreator = jtc; +} + // intclient.h EXPORT int jack_internal_client_new (const char *client_name, const char *load_name, diff --git a/common/JackGlobals.cpp b/common/JackGlobals.cpp index ef005b9e..219da5d6 100644 --- a/common/JackGlobals.cpp +++ b/common/JackGlobals.cpp @@ -32,4 +32,6 @@ JackMutex* JackGlobals::fOpenMutex = new JackMutex(); bool JackGlobals::fServerRunning = false; JackClient* JackGlobals::fClientTable[CLIENT_NUM] = {}; +jack_thread_creator_t JackGlobals::fJackThreadCreator = pthread_create; + } // end of namespace diff --git a/common/JackGlobals.h b/common/JackGlobals.h index 5b109ed9..53d0591c 100644 --- a/common/JackGlobals.h +++ b/common/JackGlobals.h @@ -36,6 +36,7 @@ struct JackGlobals { static JackMutex* fOpenMutex; static bool fServerRunning; static JackClient* fClientTable[]; + static jack_thread_creator_t fJackThreadCreator; }; diff --git a/common/jack/thread.h b/common/jack/thread.h index 9ff84b98..460eb0a7 100644 --- a/common/jack/thread.h +++ b/common/jack/thread.h @@ -117,6 +117,29 @@ int jack_client_stop_thread(jack_client_t* client, pthread_t thread); */ int jack_client_kill_thread(jack_client_t* client, pthread_t thread); + typedef int (*jack_thread_creator_t)(pthread_t*, + const pthread_attr_t*, + void* (*function)(void*), + void* arg); +/** + * This function can be used in very very specialized cases + * where it is necessary that client threads created by JACK + * are created by something other than pthread_create(). After + * it is used, any threads that JACK needs for the client will + * will be created by calling the function passed to this + * function. + * + * No normal application/client should consider calling this. + * The specific case for which it was created involves running + * win32/x86 plugins under Wine on Linux, where it is necessary + * that all threads that might call win32 functions are known + * to Wine. + * + * @param creator a function that creates a new thread + * + */ +void jack_set_thread_creator (jack_thread_creator_t creator); + /* @} */ #ifdef __cplusplus diff --git a/posix/JackPosixThread.cpp b/posix/JackPosixThread.cpp index a1ac219e..aa1d0fbd 100644 --- a/posix/JackPosixThread.cpp +++ b/posix/JackPosixThread.cpp @@ -21,6 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "JackPosixThread.h" #include "JackError.h" #include "JackTime.h" +#include "JackGlobals.h" #include // for memset #include // for _POSIX_PRIORITY_SCHEDULING check @@ -139,7 +140,7 @@ int JackPosixThread::StartImp(pthread_t* thread, int priority, int realtime, voi return -1; } - if ((res = pthread_create(thread, &attributes, start_routine, arg))) { + if ((res = JackGlobals::fJackThreadCreator(thread, &attributes, start_routine, arg))) { jack_error("Cannot create thread res = %d err = %s", res, strerror(errno)); return -1; } diff --git a/posix/JackTypes_os.h b/posix/JackTypes_os.h index 84307c15..01e6c9b9 100644 --- a/posix/JackTypes_os.h +++ b/posix/JackTypes_os.h @@ -26,4 +26,6 @@ typedef unsigned long long UInt64; typedef pthread_key_t jack_tls_key; +typedef int (*jack_thread_creator_t)(pthread_t*, const pthread_attr_t*, void* (*function)(void*), void* arg); + #endif