- pthread_attr_t default_attr;
- bool use_default_attr = (attr == NULL);
-
- if (use_default_attr) {
- // set default stack size to sensible default for memlocking
- pthread_attr_init(&default_attr);
- pthread_attr_setstacksize(&default_attr, 500000);
- attr = &default_attr;
+
+void
+PBD::notify_event_loops_about_thread_creation (pthread_t thread, const std::string& emitting_thread_name, int request_count)
+{
+ /* notify threads that may exist in the future (they may also exist
+ * already, in which case they will catch the
+ * ThreadCreatedWithRequestSize signal)
+ */
+ EventLoop::pre_register (emitting_thread_name, request_count);
+
+ /* notify all existing threads */
+ ThreadCreatedWithRequestSize (thread, emitting_thread_name, 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;
+ }