UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
worker.h File Reference
#include <cstddef>
Include dependency graph for worker.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef void(* respawn_parallel_callback_t) (void *in, void *out, size_t data_len, void *udata)
 
typedef void *(* runnable_t) (void *)
 
typedef void * task_result_handle_t
 

Functions

void respawn_parallel (void *in, void *out, size_t nmemb, size_t size, respawn_parallel_callback_t c, void *udata)
 
task_result_handle_t task_run_async (runnable_t task, void *data)
 Runs task asynchronously.
 
void task_run_async_detached (runnable_t task, void *data)
 Runs task asynchronously in a detached state.
 
void task_run_parallel (runnable_t task, int worker_count, void *data, size_t data_size, void **res)
 
void * wait_task (task_result_handle_t handle)
 

Detailed Description

Typedef Documentation

◆ respawn_parallel_callback_t

typedef void(* respawn_parallel_callback_t) (void *in, void *out, size_t data_len, void *udata)
Parameters
data_lenin/out processed block length in bytes (multpile of respawn_parallel's size param)

Definition at line 61 of file worker.h.

◆ runnable_t

typedef void *(* runnable_t) (void *)

Definition at line 50 of file worker.h.

◆ task_result_handle_t

typedef void* task_result_handle_t

Definition at line 49 of file worker.h.

Function Documentation

◆ respawn_parallel()

void respawn_parallel ( void * in,
void * out,
size_t nmemb,
size_t size,
respawn_parallel_callback_t c,
void * udata )

Automatically respawns threads to convert in to out

Botn input and output elements must currently have the same size (can be changed in future). Option semantics is similar to qsort().

Definition at line 332 of file worker.cpp.

333{
334 const int threads = min<int>(get_cpu_core_count(), MAX_CPU_CORES);
336
337 for (int i = 0; i < threads; ++i) {
338 data[i].c = c;
339 data[i].in = (char *) in + i * (nmemb / threads) * size;
340 data[i].out = (char *) out + i * (nmemb / threads) * size;
341 data[i].data_len = (nmemb / threads) * size;
342 data[i].udata = udata;
343 if (i == threads - 1) {
344 data[i].data_len = size * (nmemb - (threads - 1) * (nmemb / threads));
345 }
346 }
347
348 task_run_parallel(respawn_parallel_task, threads, data, sizeof data[0], NULL);
349}
@ MAX_CPU_CORES
maximal expected CPU core count
Definition macros.h:132
int get_cpu_core_count(void)
Definition misc.cpp:218
#define min(a, b)
Definition rtp.c:99
respawn_parallel_callback_t c
Definition worker.cpp:315
void task_run_parallel(runnable_t task, int worker_count, void *data, size_t data_size, void **res)
Definition worker.cpp:294
static void * respawn_parallel_task(void *arg)
Definition worker.cpp:321

References respawn_parallel_data::c, respawn_parallel_data::data_len, get_cpu_core_count(), respawn_parallel_data::in, MAX_CPU_CORES, min, respawn_parallel_data::out, respawn_parallel_task(), task_run_parallel(), and respawn_parallel_data::udata.

Referenced by r10k_full_to_limited(), and r10k_limited_to_full().

Here is the call graph for this function:

◆ task_run_async()

task_result_handle_t task_run_async ( runnable_t task,
void * data )

Runs task asynchronously.

Parameters
taskcallback to be run
dataadditional data to be passed to the callback
Returns
handle to the task
Note
If you use this call wait_task() must be run.

Definition at line 262 of file worker.cpp.

263{
264 return instance.run_async(task, data, false);
265}
task_result_handle_t run_async(runnable_t task, void *data, bool detached)
Definition worker.cpp:222
static class worker_pool instance
Definition worker.cpp:250

References instance, and worker_pool::run_async().

Referenced by state_capture_filter_gamma::apply_lut(), compress_frame_tiles(), decompress_thread(), task_run_parallel(), and video_reading_thread().

Here is the call graph for this function:

◆ task_run_async_detached()

void task_run_async_detached ( runnable_t task,
void * data )

Runs task asynchronously in a detached state.

Detached task should own its resources. Moreover, it must not use any static variables/objects.

Parameters
taskcallback to be run
dataadditional data to be passed to the callback

Definition at line 275 of file worker.cpp.

276{
277 instance.run_async(task, data, true);
278}

References instance, and worker_pool::run_async().

Referenced by decode_audio_frame(), process_statistics(), and ultragrid_rtp_video_rxtx::send_frame().

Here is the call graph for this function:

◆ task_run_parallel()

void task_run_parallel ( runnable_t task,
int worker_count,
void * data,
size_t data_size,
void ** res )

This combines task_run_async() + wait_task()

Parameters
tasktask to be run
worker_countnumber of workers to be run
datapointer to data array to be passed to task
data_sizesize of element of data
res(optional) pointer to result array, may be NULL

Definition at line 294 of file worker.cpp.

295{
296 if (worker_count == 1) {
297 task(data);
298 return;
299 }
300
301 vector<task_result_handle_t> tasks(worker_count);
302 for (int i = 0; i < worker_count; ++i) {
303 tasks[i] = task_run_async(task, (void *)((char *) data + i * data_size));
304 }
305 for (int i = 0; i < worker_count; ++i) {
306 if (res != nullptr) {
307 res[i] = wait_task(tasks[i]);
308 } else {
309 wait_task(tasks[i]);
310 }
311 }
312}
void * wait_task(task_result_handle_t handle)
Definition worker.cpp:280
task_result_handle_t task_run_async(runnable_t task, void *data)
Runs task asynchronously.
Definition worker.cpp:262

References task_run_async(), and wait_task().

Referenced by av_to_uv_convert(), parallel_pix_conv(), respawn_parallel(), and to_lavc_vid_conv().

Here is the call graph for this function:

◆ wait_task()

void * wait_task ( task_result_handle_t handle)

Definition at line 280 of file worker.cpp.

281{
282 return instance.wait_task(handle);
283}
void * wait_task(task_result_handle_t handle)
Definition worker.cpp:243

References instance, and worker_pool::wait_task().

Referenced by state_capture_filter_gamma::apply_lut(), compress_frame_tiles(), decompress_thread(), task_run_parallel(), and video_reading_thread().

Here is the call graph for this function: