+static int thread_creator (pthread_t* thread_id, const pthread_attr_t* attr, void *(*function)(void*), void* arg)
+{
+#ifdef WINE_THREAD_SUPPORT
+ return wine_pthread_create (thread_id, attr, function, arg);
+#else
+ return pthread_create (thread_id, attr, function, arg);
+#endif
+}
+
+void
+PBD::notify_gui_about_thread_creation (std::string target_gui, pthread_t thread, std::string str, int request_count)
+{
+ ThreadCreatedWithRequestSize (target_gui, thread, str, request_count);
+}
+
+struct ThreadStartWithName {
+ void* (*thread_work)(void*);
+ void* arg;
+ std::string name;
+
+ ThreadStartWithName (void* (*f)(void*), void* a, const std::string& s)
+ : thread_work (f), arg (a), name (s) {}
+};
+
+static void*
+fake_thread_start (void* arg)
+{
+ ThreadStartWithName* ts = (ThreadStartWithName*) arg;
+ void* (*thread_work)(void*) = ts->thread_work;
+ void* thread_arg = ts->arg;
+
+ /* name will be deleted by the default handler for GStaticPrivate, when the thread exits */
+
+ pthread_set_name (ts->name.c_str());
+
+ /* we don't need this object anymore */
+
+ delete ts;
+
+ /* actually run the thread's work function */
+
+ void* ret = thread_work (thread_arg);
+
+ /* cleanup */
+
+ pthread_mutex_lock (&thread_map_lock);
+
+ for (ThreadMap::iterator i = all_threads.begin(); i != all_threads.end(); ++i) {
+ if (pthread_equal ((*i), pthread_self())) {
+ all_threads.erase (i);
+ break;
+ }
+ }
+
+ pthread_mutex_unlock (&thread_map_lock);
+
+ /* done */
+
+ return ret;
+}
+