int BLI_pool_get_num_threads(TaskPool *pool) { if (pool->num_threads != 0) { return pool->num_threads; } else { return BLI_task_scheduler_num_threads(pool->scheduler); } }
static float *threaded_mask_rasterize(Mask *mask, const int width, const int height) { TaskScheduler *task_scheduler = BLI_task_scheduler_get(); TaskPool *task_pool; MaskRasterHandle *handle; ThreadedMaskRasterizeState state; float *buffer; int i, num_threads = BLI_task_scheduler_num_threads(task_scheduler), scanlines_per_thread; buffer = MEM_mallocN(sizeof(float) * height * width, "rasterized mask buffer"); /* Initialize rasterization handle. */ handle = BKE_maskrasterize_handle_new(); BKE_maskrasterize_handle_init(handle, mask, width, height, true, true, true); state.handle = handle; state.buffer = buffer; state.width = width; state.height = height; task_pool = BLI_task_pool_create(task_scheduler, &state); scanlines_per_thread = height / num_threads; for (i = 0; i < num_threads; i++) { ThreadedMaskRasterizeData *data = MEM_mallocN(sizeof(ThreadedMaskRasterizeData), "threaded mask rasterize data"); data->start_scanline = i * scanlines_per_thread; if (i < num_threads - 1) { data->num_scanlines = scanlines_per_thread; } else { data->num_scanlines = height - data->start_scanline; } BLI_task_pool_push(task_pool, mask_rasterize_func, data, true, TASK_PRIORITY_LOW); } /* work and wait until tasks are done */ BLI_task_pool_work_and_wait(task_pool); /* Free memory. */ BLI_task_pool_free(task_pool); BKE_maskrasterize_handle_free(handle); return buffer; }
static void start_prefetch_threads(MovieClip *clip, int start_frame, int current_frame, int end_frame, short render_size, short render_flag, short *stop, short *do_update, float *progress) { PrefetchQueue queue; TaskScheduler *task_scheduler = BLI_task_scheduler_get(); TaskPool *task_pool; int i, tot_thread = BLI_task_scheduler_num_threads(task_scheduler); /* initialize queue */ BLI_spin_init(&queue.spin); queue.current_frame = current_frame; queue.initial_frame = current_frame; queue.start_frame = start_frame; queue.end_frame = end_frame; queue.render_size = render_size; queue.render_flag = render_flag; queue.forward = 1; queue.stop = stop; queue.do_update = do_update; queue.progress = progress; task_pool = BLI_task_pool_create(task_scheduler, &queue); for (i = 0; i < tot_thread; i++) { BLI_task_pool_push(task_pool, prefetch_task_func, clip, false, TASK_PRIORITY_LOW); } BLI_task_pool_work_and_wait(task_pool); BLI_task_pool_free(task_pool); BLI_spin_end(&queue.spin); }
static void do_sequence_proxy(void *pjv, int *build_sizes, int build_count, int *build_undistort_sizes, int build_undistort_count, short *stop, short *do_update, float *progress) { ProxyJob *pj = pjv; MovieClip *clip = pj->clip; Scene *scene = pj->scene; TaskScheduler *task_scheduler = BLI_task_scheduler_get(); TaskPool *task_pool; int sfra = SFRA, efra = EFRA; ProxyThread *handles; int i, tot_thread = BLI_task_scheduler_num_threads(task_scheduler); int width, height; ProxyQueue queue; if (build_undistort_count) { BKE_movieclip_get_size(clip, NULL, &width, &height); } BLI_spin_init(&queue.spin); queue.cfra = sfra; queue.sfra = sfra; queue.efra = efra; queue.stop = stop; queue.do_update = do_update; queue.progress = progress; task_pool = BLI_task_pool_create(task_scheduler, &queue); handles = MEM_callocN(sizeof(ProxyThread) * tot_thread, "proxy threaded handles"); for (i = 0; i < tot_thread; i++) { ProxyThread *handle = &handles[i]; handle->clip = clip; handle->build_count = build_count; handle->build_sizes = build_sizes; handle->build_undistort_count = build_undistort_count; handle->build_undistort_sizes = build_undistort_sizes; if (build_undistort_count) { handle->distortion = BKE_tracking_distortion_new(&clip->tracking, width, height); } BLI_task_pool_push(task_pool, proxy_task_func, handle, false, TASK_PRIORITY_LOW); } BLI_task_pool_work_and_wait(task_pool); BLI_task_pool_free(task_pool); if (build_undistort_count) { for (i = 0; i < tot_thread; i++) { ProxyThread *handle = &handles[i]; BKE_tracking_distortion_free(handle->distortion); } } BLI_spin_end(&queue.spin); MEM_freeN(handles); }