AttrList new_AttrList(void){ AttrList newList = INVALID_ATTRLIST; int i; if(!poolInitialized) initPool(); if(poolUsed == (poolSize - 1)) growPool(); newList = getNewID(); if(newList != INVALID_ATTRLIST){ for(i = 0; i < poolSize; ++i){ if(attrListPool[i].id == INVALID_ATTRLIST){ break; } } attrListPool[i].id = newList; if(attrListPool[i].data != NULL){ gcFree(attrListPool[i].data); } if(attrListPool[i].keys != NULL){ gcFree(attrListPool[i].keys); } attrListPool[i].size = 0; attrListPool[i].keys = NULL; attrListPool[i].data = NULL; poolUsed++; } return newList; }
ThreadPool::ThreadPool(int num) : _num_active_threads(num), _task_in_queue(1000), _task_in_queue_priority(100), _task_out_queue(1000) { _threads.reserve(num); growPool(num); }
void ThreadPool::resize(int num) { if (num < 0) num = 0; if (num > _num_active_threads) { _threads.reserve(num); growPool(num - _num_active_threads); } else if (num < _num_active_threads) { shrinkPool(_num_active_threads - num); } }