void main_loop_io_worker_init(void) { main_loop_io_workers.max_threads = MIN(MAX(MAIN_LOOP_MIN_WORKER_THREADS, get_processor_count()), MAIN_LOOP_MAX_WORKER_THREADS); main_loop_io_workers.thread_start = (void (*)(void *)) main_loop_worker_thread_start; main_loop_io_workers.thread_stop = (void (*)(void *)) main_loop_worker_thread_stop; iv_work_pool_create(&main_loop_io_workers); log_queue_set_max_threads(MIN(main_loop_io_workers.max_threads, MAIN_LOOP_MAX_WORKER_THREADS)); }
int iv_getaddrinfo_submit(struct iv_getaddrinfo *ig) { struct iv_getaddrinfo_task *igt; struct iv_getaddrinfo_thr_info *tinfo; igt = calloc(1, sizeof(*igt)); if (igt == NULL) return -1; igt->ig = ig; IV_WORK_ITEM_INIT(&igt->work); igt->work.cookie = igt; igt->work.work = iv_getaddrinfo_task_work; igt->work.completion = iv_getaddrinfo_task_complete; if (ig->node != NULL) { igt->node = strdup(ig->node); if (igt->node == NULL) { free(igt); return -1; } } if (ig->service != NULL) { igt->service = strdup(ig->service); if (igt->service == NULL) { free(igt->node); free(igt); return -1; } } if (ig->hints != NULL) { igt->hints.ai_family = ig->hints->ai_family; igt->hints.ai_socktype = ig->hints->ai_socktype; igt->hints.ai_protocol = ig->hints->ai_protocol; igt->hints.ai_flags = ig->hints->ai_flags; igt->have_hints = 1; } tinfo = iv_tls_user_ptr(&iv_getaddrinfo_tls_user); if (!tinfo->num_requests++) iv_work_pool_create(&tinfo->pool); iv_work_pool_submit_work(&tinfo->pool, &igt->work); ig->task = igt; return 0; }
int main() { iv_init(); iv_thread_set_debug_state(1); IV_WORK_POOL_INIT(&pool); pool.max_threads = 8; iv_work_pool_create(&pool); IV_WORK_ITEM_INIT(&item_a); item_a.cookie = "a"; item_a.work = work; item_a.completion = work_complete; iv_work_pool_submit_work(&pool, &item_a); IV_WORK_ITEM_INIT(&item_b); item_b.cookie = "b"; item_b.work = work; item_b.completion = work_complete; iv_work_pool_submit_work(&pool, &item_b); IV_WORK_ITEM_INIT(&item_c); item_c.cookie = "c"; item_c.work = work; item_c.completion = work_complete; iv_work_pool_submit_work(&pool, &item_c); IV_WORK_ITEM_INIT(&item_d); item_d.cookie = "d"; item_d.work = work; item_d.completion = work_complete; iv_work_pool_submit_work(&pool, &item_d); item_count = 4; iv_main(); iv_deinit(); return 0; }