diff options
author | Reimar Döffinger <Reimar.Doeffinger@gmx.de> | 2009-10-12 11:35:35 +0000 |
---|---|---|
committer | Reimar Döffinger <Reimar.Doeffinger@gmx.de> | 2009-10-12 11:35:35 +0000 |
commit | 8d23a86f3346121f64b1ce80c3e0740e05fd2b29 (patch) | |
tree | 6645c63f8ca4ca4a97da7325b758cb4a7724aee0 /libavcodec/pthread.c | |
parent | febd1c90a64c1df2d72600d0fe1f020e88d10953 (diff) | |
download | ffmpeg-8d23a86f3346121f64b1ce80c3e0740e05fd2b29.tar.gz |
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
Diffstat (limited to 'libavcodec/pthread.c')
-rw-r--r-- | libavcodec/pthread.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/libavcodec/pthread.c b/libavcodec/pthread.c index 82eba38786..556e546188 100644 --- a/libavcodec/pthread.c +++ b/libavcodec/pthread.c @@ -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; } |