Mercurial > libavcodec.hg
comparison pthread.c @ 2979:bfabfdf9ce55 libavcodec
COSMETICS: tabs --> spaces, some prettyprinting
author | diego |
---|---|
date | Thu, 22 Dec 2005 01:10:11 +0000 |
parents | ef2149182f1c |
children | 0b546eab515d |
comparison
equal
deleted
inserted
replaced
2978:403183bbb505 | 2979:bfabfdf9ce55 |
---|---|
51 int self_id; | 51 int self_id; |
52 | 52 |
53 pthread_mutex_lock(&c->current_job_lock); | 53 pthread_mutex_lock(&c->current_job_lock); |
54 self_id = c->current_job++; | 54 self_id = c->current_job++; |
55 for (;;){ | 55 for (;;){ |
56 while (our_job >= c->job_count) { | 56 while (our_job >= c->job_count) { |
57 if (c->current_job == thread_count + c->job_count) | 57 if (c->current_job == thread_count + c->job_count) |
58 pthread_cond_signal(&c->last_job_cond); | 58 pthread_cond_signal(&c->last_job_cond); |
59 | 59 |
60 pthread_cond_wait(&c->current_job_cond, &c->current_job_lock); | 60 pthread_cond_wait(&c->current_job_cond, &c->current_job_lock); |
61 our_job = self_id; | 61 our_job = self_id; |
62 | 62 |
63 if (c->done) { | 63 if (c->done) { |
64 pthread_mutex_unlock(&c->current_job_lock); | 64 pthread_mutex_unlock(&c->current_job_lock); |
65 return NULL; | 65 return NULL; |
66 } | 66 } |
67 } | 67 } |
68 pthread_mutex_unlock(&c->current_job_lock); | 68 pthread_mutex_unlock(&c->current_job_lock); |
69 | 69 |
70 c->rets[our_job%c->rets_count] = c->func(avctx, c->args[our_job]); | 70 c->rets[our_job%c->rets_count] = c->func(avctx, c->args[our_job]); |
71 | 71 |
72 pthread_mutex_lock(&c->current_job_lock); | 72 pthread_mutex_lock(&c->current_job_lock); |
73 our_job = c->current_job++; | 73 our_job = c->current_job++; |
74 } | 74 } |
75 } | 75 } |
76 | 76 |
77 static always_inline void avcodec_thread_park_workers(ThreadContext *c, int thread_count) | 77 static always_inline void avcodec_thread_park_workers(ThreadContext *c, int thread_count) |
78 { | 78 { |
114 c->job_count = job_count; | 114 c->job_count = job_count; |
115 c->args = arg; | 115 c->args = arg; |
116 c->func = func; | 116 c->func = func; |
117 if (ret) { | 117 if (ret) { |
118 c->rets = ret; | 118 c->rets = ret; |
119 c->rets_count = job_count; | 119 c->rets_count = job_count; |
120 } else { | 120 } else { |
121 c->rets = &dummy_ret; | 121 c->rets = &dummy_ret; |
122 c->rets_count = 1; | 122 c->rets_count = 1; |
123 } | 123 } |
124 pthread_cond_broadcast(&c->current_job_cond); | 124 pthread_cond_broadcast(&c->current_job_cond); |
125 | 125 |
126 avcodec_thread_park_workers(c, avctx->thread_count); | 126 avcodec_thread_park_workers(c, avctx->thread_count); |
127 | 127 |
152 pthread_cond_init(&c->last_job_cond, NULL); | 152 pthread_cond_init(&c->last_job_cond, NULL); |
153 pthread_mutex_init(&c->current_job_lock, NULL); | 153 pthread_mutex_init(&c->current_job_lock, NULL); |
154 pthread_mutex_lock(&c->current_job_lock); | 154 pthread_mutex_lock(&c->current_job_lock); |
155 for (i=0; i<thread_count; i++) { | 155 for (i=0; i<thread_count; i++) { |
156 if(pthread_create(&c->workers[i], NULL, worker, avctx)) { | 156 if(pthread_create(&c->workers[i], NULL, worker, avctx)) { |
157 avctx->thread_count = i; | 157 avctx->thread_count = i; |
158 pthread_mutex_unlock(&c->current_job_lock); | 158 pthread_mutex_unlock(&c->current_job_lock); |
159 avcodec_thread_free(avctx); | 159 avcodec_thread_free(avctx); |
160 return -1; | 160 return -1; |
161 } | 161 } |
162 } | 162 } |
163 | 163 |