FFmpeg
Macros | Functions
slicethread.c File Reference
#include <stdatomic.h>
#include "cpu.h"
#include "internal.h"
#include "slicethread.h"
#include "mem.h"
#include "thread.h"
#include "avassert.h"

Go to the source code of this file.

Macros

#define MAX_AUTO_THREADS   16
 

Functions

int avpriv_slicethread_create2 (AVSliceThread **pctx, void *priv, int(*worker_func)(void *priv, int jobnr, int threadnr, int nb_jobs, int nb_threads), int(*main_func)(void *priv), int nb_threads)
 Create slice threading context. More...
 
int avpriv_slicethread_execute2 (AVSliceThread *ctx, int nb_jobs, int execute_main)
 Execute slice threading. More...
 
void avpriv_slicethread_free (AVSliceThread **pctx)
 Destroy slice threading context. More...
 
static int wrapper_worker (void *priv, int jobnr, int threadnr, int nb_jobs, int nb_threads)
 Backwards compatibility wrapper for the deprecated avpriv_ slicethread API. More...
 
static int wrapper_main (void *priv)
 
int avpriv_slicethread_create (AVSliceThread **pctx, void *priv, void(*worker_func)(void *priv, int jobnr, int threadnr, int nb_jobs, int nb_threads), void(*main_func)(void *priv), int nb_threads)
 
void avpriv_slicethread_execute (AVSliceThread *ctx, int nb_jobs, int execute_main)
 

Macro Definition Documentation

◆ MAX_AUTO_THREADS

#define MAX_AUTO_THREADS   16

Definition at line 27 of file slicethread.c.

Function Documentation

◆ avpriv_slicethread_create2()

int avpriv_slicethread_create2 ( AVSliceThread **  pctx,
void *  priv,
int(*)(void *priv, int jobnr, int threadnr, int nb_jobs, int nb_threads)  worker_func,
int(*)(void *priv)  main_func,
int  nb_threads 
)

Create slice threading context.

Parameters
pctxslice threading context returned here
privprivate pointer to be passed to callback function
worker_funccallback function to be executed
main_funcspecial callback function, called from main thread, may be NULL
nb_threadsnumber of threads, 0 for automatic, must be >= 0
Returns
return number of threads or negative AVERROR on failure

Definition at line 283 of file slicethread.c.

Referenced by avpriv_slicethread_create(), context_init_threaded(), ff_slice_thread_init(), ff_sws_color_map_generate_dynamic(), ff_sws_graph_init(), ff_sws_thread_exec(), and thread_init_internal().

◆ avpriv_slicethread_execute2()

int avpriv_slicethread_execute2 ( AVSliceThread ctx,
int  nb_jobs,
int  execute_main 
)

Execute slice threading.

If any job returns a nonzero value, all remaining jobs will be aborted and that value returned.

If main_func itself returns a nonzero value, that value is guaranteed to be returned, even if a worker thread returns a nonzero value first.

Parameters
ctxslice threading context
nb_jobsnumber of jobs, must be > 0
execute_mainalso execute main_func
Returns
0 on success, else first seen return value

Definition at line 292 of file slicethread.c.

Referenced by avpriv_slicethread_execute(), ff_sws_color_map_generate_dynamic(), ff_sws_graph_run(), ff_sws_thread_exec(), sws_receive_slice(), and thread_execute().

◆ avpriv_slicethread_free()

void avpriv_slicethread_free ( AVSliceThread **  pctx)

Destroy slice threading context.

Parameters
pctxpointer to context

Definition at line 297 of file slicethread.c.

Referenced by ff_slice_thread_free(), ff_sws_color_map_generate_dynamic(), ff_sws_thread_exec(), graph_uninit(), slice_thread_uninit(), sws_freeContext(), and thread_init_internal().

◆ wrapper_worker()

static int wrapper_worker ( void *  priv,
int  jobnr,
int  threadnr,
int  nb_jobs,
int  nb_threads 
)
static

Backwards compatibility wrapper for the deprecated avpriv_ slicethread API.

Definition at line 310 of file slicethread.c.

Referenced by avpriv_slicethread_create().

◆ wrapper_main()

static int wrapper_main ( void *  priv)
static

Definition at line 317 of file slicethread.c.

Referenced by avpriv_slicethread_create().

◆ avpriv_slicethread_create()

int avpriv_slicethread_create ( AVSliceThread **  pctx,
void *  priv,
void(*)(void *priv, int jobnr, int threadnr, int nb_jobs, int nb_threads)  worker_func,
void(*)(void *priv)  main_func,
int  nb_threads 
)
Deprecated:
Wrapper around avpriv_slicethread_create2() for ABI backwards compatibility.

Definition at line 324 of file slicethread.c.

◆ avpriv_slicethread_execute()

void avpriv_slicethread_execute ( AVSliceThread ctx,
int  nb_jobs,
int  execute_main 
)
Deprecated:
Wrapper around avpriv_slicethread_execute2() for ABI backwards compatibility.

Definition at line 342 of file slicethread.c.