| 154 | } |
| 155 | |
| 156 | av_cold FFExecutor* ff_executor_alloc(const FFTaskCallbacks *cb, int thread_count) |
| 157 | { |
| 158 | FFExecutor *e; |
| 159 | int has_lock = 0, has_cond = 0; |
| 160 | if (!cb || !cb->user_data || !cb->run || !cb->priorities) |
| 161 | return NULL; |
| 162 | |
| 163 | e = av_mallocz(sizeof(*e)); |
| 164 | if (!e) |
| 165 | return NULL; |
| 166 | e->cb = *cb; |
| 167 | |
| 168 | e->local_contexts = av_calloc(FFMAX(thread_count, 1), e->cb.local_context_size); |
| 169 | if (!e->local_contexts) |
| 170 | goto free_executor; |
| 171 | |
| 172 | e->q = av_calloc(e->cb.priorities, sizeof(Queue)); |
| 173 | if (!e->q) |
| 174 | goto free_executor; |
| 175 | |
| 176 | e->threads = av_calloc(FFMAX(thread_count, 1), sizeof(*e->threads)); |
| 177 | if (!e->threads) |
| 178 | goto free_executor; |
| 179 | |
| 180 | if (!thread_count) |
| 181 | return e; |
| 182 | |
| 183 | has_lock = !ff_mutex_init(&e->lock, NULL); |
| 184 | has_cond = !ff_cond_init(&e->cond, NULL); |
| 185 | |
| 186 | if (!has_lock || !has_cond) |
| 187 | goto free_executor; |
| 188 | |
| 189 | for (/* nothing */; e->thread_count < thread_count; e->thread_count++) { |
| 190 | ThreadInfo *ti = e->threads + e->thread_count; |
| 191 | ti->e = e; |
| 192 | if (executor_thread_create(&ti->thread, NULL, executor_worker_task, ti)) |
| 193 | goto free_executor; |
| 194 | } |
| 195 | return e; |
| 196 | |
| 197 | free_executor: |
| 198 | executor_free(e, has_lock, has_cond); |
| 199 | return NULL; |
| 200 | } |
| 201 | |
| 202 | av_cold void ff_executor_free(FFExecutor **executor) |
| 203 | { |
no test coverage detected