Add an execute2 function that is more flexible and allows to use parallel
processing with jobs > threads without wasting too much memory. It also avoids needing a separate int array when the only additional data the jobs needs is a single int running from 0 to count-1. Originally committed as revision 20210 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
@@ -26,10 +26,12 @@
|
||||
#include "avcodec.h"
|
||||
|
||||
typedef int (action_func)(AVCodecContext *c, void *arg);
|
||||
typedef int (action_func2)(AVCodecContext *c, void *arg, int jobnr, int threadnr);
|
||||
|
||||
typedef struct ThreadContext {
|
||||
pthread_t *workers;
|
||||
action_func *func;
|
||||
action_func2 *func2;
|
||||
void *args;
|
||||
int *rets;
|
||||
int rets_count;
|
||||
@@ -68,7 +70,8 @@ static void* attribute_align_arg worker(void *v)
|
||||
}
|
||||
pthread_mutex_unlock(&c->current_job_lock);
|
||||
|
||||
c->rets[our_job%c->rets_count] = c->func(avctx, (char*)c->args + our_job*c->job_size);
|
||||
c->rets[our_job%c->rets_count] = c->func ? c->func(avctx, (char*)c->args + our_job*c->job_size):
|
||||
c->func2(avctx, c->args, our_job, self_id);
|
||||
|
||||
pthread_mutex_lock(&c->current_job_lock);
|
||||
our_job = c->current_job++;
|
||||
@@ -130,6 +133,13 @@ int avcodec_thread_execute(AVCodecContext *avctx, action_func* func, void *arg,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int avcodec_thread_execute2(AVCodecContext *avctx, action_func2* func2, void *arg, int *ret, int job_count)
|
||||
{
|
||||
ThreadContext *c= avctx->thread_opaque;
|
||||
c->func2 = func2;
|
||||
return avcodec_thread_execute(avctx, NULL, arg, ret, job_count, 0);
|
||||
}
|
||||
|
||||
int avcodec_thread_init(AVCodecContext *avctx, int thread_count)
|
||||
{
|
||||
int i;
|
||||
@@ -167,5 +177,6 @@ int avcodec_thread_init(AVCodecContext *avctx, int thread_count)
|
||||
avcodec_thread_park_workers(c, thread_count);
|
||||
|
||||
avctx->execute = avcodec_thread_execute;
|
||||
avctx->execute2 = avcodec_thread_execute2;
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user