task_processor_thread* task_processor_thread_pool_get( task_processor_thread_pool* pool ) { task_processor_thread* thread = NULL; synchronize_lock_mutex( pool->mutex ); if ( ARRAY_LIST_IS_EMPTY( &pool->threads )) { thread = object_pool_alloc( &pool->processor_thread_pool ); if ( NULL == thread ) { synchronize_unlock_mutex( pool->mutex ); return NULL; } if ( !task_processor_thread_initialize( thread ) ) { object_pool_free( &pool->processor_thread_pool, thread ); synchronize_unlock_mutex( pool->mutex ); return NULL; } } else { thread = *(task_processor_thread**)array_list_last( &pool->threads ); ASSERT( NULL != thread ); array_list_pop( &pool->threads ); } synchronize_unlock_mutex( pool->mutex ); task_processor_thread_continue( thread ); return thread; }
Object array_pop(Array * const list) { return array_list_pop((ArrayList * const ) list); }