static void * direct_thread_main( void *arg ) { void *ret; DirectThread *thread = arg; prctl( PR_SET_NAME, thread->name, 0, 0, 0 ); pthread_setspecific( thread_key, thread ); D_DEBUG_AT( Direct_ThreadInit, "%s( %p )\n", __FUNCTION__, arg ); D_DEBUG_AT( Direct_ThreadInit, " -> starting...\n" ); D_MAGIC_ASSERT( thread, DirectThread ); pthread_cleanup_push( direct_thread_cleanup, thread ); thread->tid = direct_gettid(); D_DEBUG_AT( Direct_ThreadInit, " -> tid %d\n", thread->tid ); __D_direct_thread_call_init_handlers( thread ); /* Have all signals handled by the main thread. */ if (direct_config->thread_block_signals) direct_signals_block_all(); /* Lock the thread mutex. */ D_DEBUG_AT( Direct_ThreadInit, " -> locking...\n" ); direct_mutex_lock( &thread->lock ); /* Indicate that our initialization has completed. */ D_ASSERT( !thread->init ); thread->init = true; D_DEBUG_AT( Direct_ThreadInit, " -> signalling...\n" ); direct_waitqueue_signal( &thread->cond ); /* Unlock the thread mutex. */ D_DEBUG_AT( Direct_ThreadInit, " -> unlocking...\n" ); direct_mutex_unlock( &thread->lock ); if (thread->joining) { D_DEBUG_AT( Direct_Thread, " -> Being joined before entering main routine!\n" ); return NULL; } D_MAGIC_ASSERT( thread, DirectThread ); /* Call main routine. */ D_DEBUG_AT( Direct_ThreadInit, " -> running...\n" ); ret = thread->main( thread, thread->arg ); D_DEBUG_AT( Direct_Thread, " -> Returning %p from '%s' (%s, %d)...\n", ret, thread->name, direct_thread_type_name(thread->type), thread->tid ); D_MAGIC_ASSERT( thread, DirectThread ); pthread_cleanup_pop( 1 ); return ret; }
static void * direct_thread_main( void *arg ) { void *ret; DirectThread *thread = arg; DirectThreadInitHandler *handler; pid_t tid; tid = direct_gettid(); D_DEBUG_AT( Direct_ThreadInit, "%s( %p ) <- tid %d\n", __FUNCTION__, arg, tid ); D_DEBUG_AT( Direct_ThreadInit, " -> starting...\n" ); D_MAGIC_ASSERT( thread, DirectThread ); pthread_cleanup_push( direct_thread_cleanup, thread ); pthread_setspecific( thread_key, thread ); thread->tid = tid; /* Call all init handlers. */ pthread_mutex_lock( &handler_lock ); direct_list_foreach (handler, handlers) handler->func( thread, handler->arg ); pthread_mutex_unlock( &handler_lock ); /* Have all signals handled by the main thread. */ if (direct_config->thread_block_signals) direct_signals_block_all(); /* Lock the thread mutex. */ D_DEBUG_AT( Direct_ThreadInit, " -> locking...\n" ); pthread_mutex_lock( &thread->lock ); /* Indicate that our initialization has completed. */ thread->init = true; #ifdef DIRECT_THREAD_WAIT_INIT D_DEBUG_AT( Direct_ThreadInit, " -> signalling...\n" ); pthread_cond_signal( &thread->cond ); #endif /* Unlock the thread mutex. */ D_DEBUG_AT( Direct_ThreadInit, " -> unlocking...\n" ); pthread_mutex_unlock( &thread->lock ); if (thread->joining) { D_DEBUG_AT( Direct_Thread, " -> Being joined before entering main routine!\n" ); return NULL; } D_MAGIC_ASSERT( thread, DirectThread ); /* Call main routine. */ D_DEBUG_AT( Direct_ThreadInit, " -> running...\n" ); ret = thread->main( thread, thread->arg ); D_DEBUG_AT( Direct_Thread, " -> Returning %p from '%s' (%s, %d)...\n", ret, thread->name, direct_thread_type_name(thread->type), thread->tid ); D_MAGIC_ASSERT( thread, DirectThread ); pthread_cleanup_pop( 1 ); return ret; }