void particlesInit(struct particle_system *ps, int nbparticles, int nbemitters, int nbforces) { poolInit(&ps->particles, nbparticles, sizeof(struct particle)); ps->nbemitters = nbemitters; if(nbemitters > 0) { ps->emit = malloc(sizeof(struct particle_emitter)*nbemitters); } else { ps->emit = NULL; } ps->nbforces = nbforces; if(nbforces > 0) { ps->forces = malloc(sizeof(struct particle_force)*nbforces); } else { ps->forces = NULL; } }
Http::Http(int num):fpwUrl(NULL), maxthreadnum(num) { signal(SIGPIPE, &signalHandler); openFile(fpwUrl, "./text", "w+"); openFile(fprArg, "./config", "r"); openFile(test, "./test", "r"); configInit(); std::unordered_set<std::string>::iterator itr = jobUrl.begin(); pthis = this; curl_global_init(CURL_GLOBAL_ALL); try { poolInit(maxthreadnum); while (true) { if (itr == jobUrl.end() || itr->empty()) { sleep(1); itr = jobUrl.begin(); continue; } char* p = (char*)malloc(itr->size()+1); if (p == NULL) { std::cout << "continue url=" << *itr << std::endl; itr = jobUrl.erase(itr); continue; } memset(p, 0, itr->size()+1); memcpy(p, itr->c_str(), itr->size()); poolAddWorker(workJob, (void*)p); std::cout << "加入任务" << std::endl; //throw std::string("exit"); //测试 pthread_mutex_lock(&(pthis->pthreadpool.queuelock)); itr = jobUrl.erase(itr); pthread_mutex_unlock(&(pthis->pthreadpool.queuelock)); } } catch (std::string& ex){ std::cout << "catch="; std::cout << ex << std::endl; } }
void libdwPoolInit(void) { pool = poolInit(pool_size, pool_size, (alloc_thing_fn) libdwInit, (free_thing_fn) libdwFree); }