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; }
event_group_element_type synchronize_event_group_add_element( event_group_type _group ) { synchronize_event_group* group = _group; synchronize_event_group_element* element = NULL; pthread_mutex_lock( &(group->mutex) ); element = object_pool_alloc( &group->objpool ); if ( !list_push_back( &group->elements, &element ) ) { object_pool_free( &group->objpool, element ); pthread_mutex_unlock( &(group->mutex) ); return FALSE; } element->group = group; element->flag = FALSE; pthread_mutex_unlock( &(group->mutex) ); return element; }
void task_processor_thread_pool_put( task_processor_thread_pool* pool, task_processor_thread* thread ) { task_processor_thread** p = NULL; ASSERT( NULL != thread ); task_processor_thread_pause( thread ); synchronize_lock_mutex( pool->mutex ); if ( ARRAY_LIST_SIZE( &pool->threads ) < pool->max_size ) { p = (task_processor_thread**)array_list_push( &pool->threads ); if ( NULL != p ) { *p = thread; synchronize_unlock_mutex( pool->mutex ); return; } } task_processor_thread_destroy( thread ); object_pool_free( &pool->processor_thread_pool, thread ); synchronize_unlock_mutex( pool->mutex ); }
void synchronize_event_group_remove_element( event_group_type _group, event_group_element_type _element ) { synchronize_event_group* group = _group; list_iterator iter; synchronize_event_group_element* element = NULL; pthread_mutex_lock( &(group->mutex) ); LIST_ITERATOR_START( iter, &group->elements ); while ( LIST_ITERATOR_IS_VALID(iter) ) { element = *(synchronize_event_group_element**)LIST_ITERATOR_GET(iter); if ( element == _element ) { list_remove( &group->elements, iter ); object_pool_free( &group->objpool, element ); pthread_cond_broadcast( &(group->cond) ); break; } LIST_ITERATOR_NEXT(iter); } pthread_mutex_unlock( &(group->mutex) ); }
void ray_of_death_dtor( ray_of_death_t *ray_of_death ) { object_pool_free(&game_bodies, ray_of_death); }
void explore_node_map_free_node( explore_node_map* map, void* node ) { object_pool_free( &map->node_pool, node ); }