| 140 | } |
| 141 | |
| 142 | AVExecutor* av_executor_alloc(const AVTaskCallbacks *cb, int thread_count) |
| 143 | { |
| 144 | AVExecutor *e; |
| 145 | int has_lock = 0, has_cond = 0; |
| 146 | if (!cb || !cb->user_data || !cb->ready || !cb->run || !cb->priority_higher) |
| 147 | return NULL; |
| 148 | |
| 149 | e = av_mallocz(sizeof(*e)); |
| 150 | if (!e) |
| 151 | return NULL; |
| 152 | e->cb = *cb; |
| 153 | |
| 154 | e->local_contexts = av_calloc(FFMAX(thread_count, 1), e->cb.local_context_size); |
| 155 | if (!e->local_contexts) |
| 156 | goto free_executor; |
| 157 | |
| 158 | e->threads = av_calloc(FFMAX(thread_count, 1), sizeof(*e->threads)); |
| 159 | if (!e->threads) |
| 160 | goto free_executor; |
| 161 | |
| 162 | if (!thread_count) |
| 163 | return e; |
| 164 | |
| 165 | has_lock = !ff_mutex_init(&e->lock, NULL); |
| 166 | has_cond = !ff_cond_init(&e->cond, NULL); |
| 167 | |
| 168 | if (!has_lock || !has_cond) |
| 169 | goto free_executor; |
| 170 | |
| 171 | for (/* nothing */; e->thread_count < thread_count; e->thread_count++) { |
| 172 | ThreadInfo *ti = e->threads + e->thread_count; |
| 173 | ti->e = e; |
| 174 | if (executor_thread_create(&ti->thread, NULL, executor_worker_task, ti)) |
| 175 | goto free_executor; |
| 176 | } |
| 177 | return e; |
| 178 | |
| 179 | free_executor: |
| 180 | executor_free(e, has_lock, has_cond); |
| 181 | return NULL; |
| 182 | } |
| 183 | |
| 184 | void av_executor_free(AVExecutor **executor) |
| 185 | { |
nothing calls this directly
no test coverage detected