annotate pthread.c @ 12463:04e68eb1aab7 libavcodec

Check rc_buffer_size value using integer arithmetic Using floating-point here can cause erroneous rejection of parameters due to rounding errors leading to a slightly too large result. This fixes the mxf regression test with gcc 4.5 on x86_32.
author mru
date Tue, 07 Sep 2010 19:54:48 +0000
parents 7bfe7456e372
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1799
95612d423fde multithreaded/SMP motion estimation
michael
parents:
diff changeset
1 /*
8629
04423b2f6e0b cosmetics: Remove pointless period after copyright statement non-sentences.
diego
parents: 8333
diff changeset
2 * Copyright (c) 2004 Roman Shaposhnik
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2035
diff changeset
3 *
2023
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
4 * Many thanks to Steven M. Schultz for providing clever ideas and
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
5 * to Michael Niedermayer <michaelni@gmx.at> for writing initial
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
6 * implementation.
1799
95612d423fde multithreaded/SMP motion estimation
michael
parents:
diff changeset
7 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
8 * This file is part of FFmpeg.
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
9 *
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
10 * FFmpeg is free software; you can redistribute it and/or
1799
95612d423fde multithreaded/SMP motion estimation
michael
parents:
diff changeset
11 * modify it under the terms of the GNU Lesser General Public
95612d423fde multithreaded/SMP motion estimation
michael
parents:
diff changeset
12 * License as published by the Free Software Foundation; either
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
13 * version 2.1 of the License, or (at your option) any later version.
1799
95612d423fde multithreaded/SMP motion estimation
michael
parents:
diff changeset
14 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
15 * FFmpeg is distributed in the hope that it will be useful,
1799
95612d423fde multithreaded/SMP motion estimation
michael
parents:
diff changeset
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
95612d423fde multithreaded/SMP motion estimation
michael
parents:
diff changeset
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
95612d423fde multithreaded/SMP motion estimation
michael
parents:
diff changeset
18 * Lesser General Public License for more details.
95612d423fde multithreaded/SMP motion estimation
michael
parents:
diff changeset
19 *
95612d423fde multithreaded/SMP motion estimation
michael
parents:
diff changeset
20 * You should have received a copy of the GNU Lesser General Public
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
21 * License along with FFmpeg; if not, write to the Free Software
3036
0b546eab515d Update licensing information: The FSF changed postal address.
diego
parents: 2979
diff changeset
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1799
95612d423fde multithreaded/SMP motion estimation
michael
parents:
diff changeset
23 */
95612d423fde multithreaded/SMP motion estimation
michael
parents:
diff changeset
24 #include <pthread.h>
95612d423fde multithreaded/SMP motion estimation
michael
parents:
diff changeset
25
95612d423fde multithreaded/SMP motion estimation
michael
parents:
diff changeset
26 #include "avcodec.h"
95612d423fde multithreaded/SMP motion estimation
michael
parents:
diff changeset
27
8333
09aafff47bc0 Avoid invasion of POSIX-reserved _t namespace.
diego
parents: 8129
diff changeset
28 typedef int (action_func)(AVCodecContext *c, void *arg);
10386
98501365c3aa Add an execute2 function that is more flexible and allows to use parallel
reimar
parents: 8629
diff changeset
29 typedef int (action_func2)(AVCodecContext *c, void *arg, int jobnr, int threadnr);
1857
00a6bfc81010 count > thread_count for execute()
michael
parents: 1822
diff changeset
30
2023
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
31 typedef struct ThreadContext {
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
32 pthread_t *workers;
8333
09aafff47bc0 Avoid invasion of POSIX-reserved _t namespace.
diego
parents: 8129
diff changeset
33 action_func *func;
10386
98501365c3aa Add an execute2 function that is more flexible and allows to use parallel
reimar
parents: 8629
diff changeset
34 action_func2 *func2;
8129
a9734fe0811e Making it easier to send arbitrary structures as work orders to MT workers
romansh
parents: 5542
diff changeset
35 void *args;
2023
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
36 int *rets;
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
37 int rets_count;
1857
00a6bfc81010 count > thread_count for execute()
michael
parents: 1822
diff changeset
38 int job_count;
8129
a9734fe0811e Making it easier to send arbitrary structures as work orders to MT workers
romansh
parents: 5542
diff changeset
39 int job_size;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2035
diff changeset
40
2023
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
41 pthread_cond_t last_job_cond;
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
42 pthread_cond_t current_job_cond;
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
43 pthread_mutex_t current_job_lock;
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
44 int current_job;
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
45 int done;
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
46 } ThreadContext;
1799
95612d423fde multithreaded/SMP motion estimation
michael
parents:
diff changeset
47
5542
b0a566346fb1 Add attribute that forces alignment of stack to functions that need it.
ramiro
parents: 5232
diff changeset
48 static void* attribute_align_arg worker(void *v)
2023
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
49 {
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
50 AVCodecContext *avctx = v;
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
51 ThreadContext *c = avctx->thread_opaque;
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
52 int our_job = c->job_count;
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
53 int thread_count = avctx->thread_count;
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
54 int self_id;
1799
95612d423fde multithreaded/SMP motion estimation
michael
parents:
diff changeset
55
2023
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
56 pthread_mutex_lock(&c->current_job_lock);
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
57 self_id = c->current_job++;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2035
diff changeset
58 for (;;){
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
59 while (our_job >= c->job_count) {
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
60 if (c->current_job == thread_count + c->job_count)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
61 pthread_cond_signal(&c->last_job_cond);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2035
diff changeset
62
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
63 pthread_cond_wait(&c->current_job_cond, &c->current_job_lock);
2023
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
64 our_job = self_id;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2035
diff changeset
65
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
66 if (c->done) {
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
67 pthread_mutex_unlock(&c->current_job_lock);
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
68 return NULL;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
69 }
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
70 }
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
71 pthread_mutex_unlock(&c->current_job_lock);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2035
diff changeset
72
10386
98501365c3aa Add an execute2 function that is more flexible and allows to use parallel
reimar
parents: 8629
diff changeset
73 c->rets[our_job%c->rets_count] = c->func ? c->func(avctx, (char*)c->args + our_job*c->job_size):
98501365c3aa Add an execute2 function that is more flexible and allows to use parallel
reimar
parents: 8629
diff changeset
74 c->func2(avctx, c->args, our_job, self_id);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2035
diff changeset
75
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
76 pthread_mutex_lock(&c->current_job_lock);
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
77 our_job = c->current_job++;
1799
95612d423fde multithreaded/SMP motion estimation
michael
parents:
diff changeset
78 }
95612d423fde multithreaded/SMP motion estimation
michael
parents:
diff changeset
79 }
95612d423fde multithreaded/SMP motion estimation
michael
parents:
diff changeset
80
4283
d6f83e2f8804 rename always_inline to av_always_inline and move to common.h
mru
parents: 3947
diff changeset
81 static av_always_inline void avcodec_thread_park_workers(ThreadContext *c, int thread_count)
2023
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
82 {
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
83 pthread_cond_wait(&c->last_job_cond, &c->current_job_lock);
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
84 pthread_mutex_unlock(&c->current_job_lock);
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
85 }
1799
95612d423fde multithreaded/SMP motion estimation
michael
parents:
diff changeset
86
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2035
diff changeset
87 void avcodec_thread_free(AVCodecContext *avctx)
2023
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
88 {
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
89 ThreadContext *c = avctx->thread_opaque;
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
90 int i;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2035
diff changeset
91
2023
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
92 pthread_mutex_lock(&c->current_job_lock);
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
93 c->done = 1;
2035
e1b69326ae36 10l fixes by ("Debabrata Banerjee" <davatar at comcast dot net>)
michael
parents: 2023
diff changeset
94 pthread_cond_broadcast(&c->current_job_cond);
2023
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
95 pthread_mutex_unlock(&c->current_job_lock);
1857
00a6bfc81010 count > thread_count for execute()
michael
parents: 1822
diff changeset
96
2023
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
97 for (i=0; i<avctx->thread_count; i++)
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
98 pthread_join(c->workers[i], NULL);
1857
00a6bfc81010 count > thread_count for execute()
michael
parents: 1822
diff changeset
99
2023
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
100 pthread_mutex_destroy(&c->current_job_lock);
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
101 pthread_cond_destroy(&c->current_job_cond);
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
102 pthread_cond_destroy(&c->last_job_cond);
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
103 av_free(c->workers);
5232
238b95c5ffe2 set thread_opaque to NULL when freeing it
benoit
parents: 5215
diff changeset
104 av_freep(&avctx->thread_opaque);
1799
95612d423fde multithreaded/SMP motion estimation
michael
parents:
diff changeset
105 }
95612d423fde multithreaded/SMP motion estimation
michael
parents:
diff changeset
106
11492
7bfe7456e372 Remove avcodec_thread_execute from avcodec.h, and make static functions that
benoit
parents: 11405
diff changeset
107 static int avcodec_thread_execute(AVCodecContext *avctx, action_func* func, void *arg, int *ret, int job_count, int job_size)
2023
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
108 {
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
109 ThreadContext *c= avctx->thread_opaque;
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
110 int dummy_ret;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2035
diff changeset
111
2023
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
112 if (job_count <= 0)
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
113 return 0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2035
diff changeset
114
2023
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
115 pthread_mutex_lock(&c->current_job_lock);
1799
95612d423fde multithreaded/SMP motion estimation
michael
parents:
diff changeset
116
2023
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
117 c->current_job = avctx->thread_count;
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
118 c->job_count = job_count;
8129
a9734fe0811e Making it easier to send arbitrary structures as work orders to MT workers
romansh
parents: 5542
diff changeset
119 c->job_size = job_size;
2023
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
120 c->args = arg;
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
121 c->func = func;
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
122 if (ret) {
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
123 c->rets = ret;
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
124 c->rets_count = job_count;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2035
diff changeset
125 } else {
2023
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
126 c->rets = &dummy_ret;
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
127 c->rets_count = 1;
1799
95612d423fde multithreaded/SMP motion estimation
michael
parents:
diff changeset
128 }
2023
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
129 pthread_cond_broadcast(&c->current_job_cond);
1857
00a6bfc81010 count > thread_count for execute()
michael
parents: 1822
diff changeset
130
2023
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
131 avcodec_thread_park_workers(c, avctx->thread_count);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2035
diff changeset
132
1799
95612d423fde multithreaded/SMP motion estimation
michael
parents:
diff changeset
133 return 0;
95612d423fde multithreaded/SMP motion estimation
michael
parents:
diff changeset
134 }
95612d423fde multithreaded/SMP motion estimation
michael
parents:
diff changeset
135
11405
8de15f200be8 Make avcodec_thread_execute2() static
andoma
parents: 10954
diff changeset
136 static int avcodec_thread_execute2(AVCodecContext *avctx, action_func2* func2, void *arg, int *ret, int job_count)
10386
98501365c3aa Add an execute2 function that is more flexible and allows to use parallel
reimar
parents: 8629
diff changeset
137 {
98501365c3aa Add an execute2 function that is more flexible and allows to use parallel
reimar
parents: 8629
diff changeset
138 ThreadContext *c= avctx->thread_opaque;
98501365c3aa Add an execute2 function that is more flexible and allows to use parallel
reimar
parents: 8629
diff changeset
139 c->func2 = func2;
98501365c3aa Add an execute2 function that is more flexible and allows to use parallel
reimar
parents: 8629
diff changeset
140 return avcodec_thread_execute(avctx, NULL, arg, ret, job_count, 0);
98501365c3aa Add an execute2 function that is more flexible and allows to use parallel
reimar
parents: 8629
diff changeset
141 }
98501365c3aa Add an execute2 function that is more flexible and allows to use parallel
reimar
parents: 8629
diff changeset
142
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2035
diff changeset
143 int avcodec_thread_init(AVCodecContext *avctx, int thread_count)
2023
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
144 {
1799
95612d423fde multithreaded/SMP motion estimation
michael
parents:
diff changeset
145 int i;
95612d423fde multithreaded/SMP motion estimation
michael
parents:
diff changeset
146 ThreadContext *c;
95612d423fde multithreaded/SMP motion estimation
michael
parents:
diff changeset
147
10954
d7ef6611a49e Always call avcodec_thread_init()
mru
parents: 10386
diff changeset
148 avctx->thread_count = thread_count;
d7ef6611a49e Always call avcodec_thread_init()
mru
parents: 10386
diff changeset
149
d7ef6611a49e Always call avcodec_thread_init()
mru
parents: 10386
diff changeset
150 if (thread_count <= 1)
d7ef6611a49e Always call avcodec_thread_init()
mru
parents: 10386
diff changeset
151 return 0;
d7ef6611a49e Always call avcodec_thread_init()
mru
parents: 10386
diff changeset
152
2023
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
153 c = av_mallocz(sizeof(ThreadContext));
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
154 if (!c)
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
155 return -1;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2035
diff changeset
156
2023
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
157 c->workers = av_mallocz(sizeof(pthread_t)*thread_count);
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
158 if (!c->workers) {
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
159 av_free(c);
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
160 return -1;
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
161 }
1799
95612d423fde multithreaded/SMP motion estimation
michael
parents:
diff changeset
162
2023
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
163 avctx->thread_opaque = c;
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
164 c->current_job = 0;
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
165 c->job_count = 0;
8129
a9734fe0811e Making it easier to send arbitrary structures as work orders to MT workers
romansh
parents: 5542
diff changeset
166 c->job_size = 0;
2023
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
167 c->done = 0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2035
diff changeset
168 pthread_cond_init(&c->current_job_cond, NULL);
2023
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
169 pthread_cond_init(&c->last_job_cond, NULL);
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
170 pthread_mutex_init(&c->current_job_lock, NULL);
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
171 pthread_mutex_lock(&c->current_job_lock);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2035
diff changeset
172 for (i=0; i<thread_count; i++) {
2023
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
173 if(pthread_create(&c->workers[i], NULL, worker, avctx)) {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
174 avctx->thread_count = i;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
175 pthread_mutex_unlock(&c->current_job_lock);
2023
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
176 avcodec_thread_free(avctx);
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
177 return -1;
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
178 }
1799
95612d423fde multithreaded/SMP motion estimation
michael
parents:
diff changeset
179 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2035
diff changeset
180
2023
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
181 avcodec_thread_park_workers(c, thread_count);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2035
diff changeset
182
2023
50e92cec1b84 * reimplementation using mutexes and condition variables.
romansh
parents: 1857
diff changeset
183 avctx->execute = avcodec_thread_execute;
10386
98501365c3aa Add an execute2 function that is more flexible and allows to use parallel
reimar
parents: 8629
diff changeset
184 avctx->execute2 = avcodec_thread_execute2;
1799
95612d423fde multithreaded/SMP motion estimation
michael
parents:
diff changeset
185 return 0;
95612d423fde multithreaded/SMP motion estimation
michael
parents:
diff changeset
186 }