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; }
/** * \brief Initializes the whole lowlevel system. * * Initializes the graphics, the audio system, * the data file system, etc. * * \param argc number of command line arguments * \param argv command line arguments */ void System::initialize(int argc, char** argv) { #ifdef SOLARUS_USE_APPLE_POOL // initialize pool if any initPool(); #endif // initialize SDL SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK); // files FileTools::initialize(argc, argv); // video VideoManager::initialize(argc, argv); Color::initialize(); TextSurface::initialize(); Sprite::initialize(); // audio Sound::initialize(argc, argv); // input InputEvent::initialize(); // random number generator Random::initialize(); }
CThreadPool::ThreadPool(int threadNo) { timeout = 10; if (pthread_cond_init(&release_cond, NULL)) std::cout << "pthread_cond_init failed!" << std::endl; if (pthread_cond_init(&worker_cond, NULL)) std::cout << "pthread_cond_init failed!" << std::endl; initPool(threadNo); }
bool init(size_t num_threads) { if (m_running.exchange(true)) return false; m_db_pool = initPool(); if (!m_db_pool) { return false; } for (size_t i = 0; i != num_threads; ++i) { m_threads.push_back(std::thread(&DBService::threadStart, this)); } return true; }
void test_sharding(const std::string& arg, int num) { if (!initPool()) { LOG4CXX_ERROR(logger, "pool is not ready !"); return ; } boost::thread_group thrds; for (int i = 0; i < num; i++) { if ("get" == arg) { thrds.create_thread(test_get); } else if ("set" == arg) { thrds.create_thread(test_set); } } thrds.join_all(); }