|
@@ -82,9 +82,11 @@ static int run_one_task(AVExecutor *e, void *lc)
|
|
/* nothing */;
|
|
/* nothing */;
|
|
if (*prev) {
|
|
if (*prev) {
|
|
AVTask *t = remove_task(prev, *prev);
|
|
AVTask *t = remove_task(prev, *prev);
|
|
- ff_mutex_unlock(&e->lock);
|
|
|
|
|
|
+ if (e->thread_count > 0)
|
|
|
|
+ ff_mutex_unlock(&e->lock);
|
|
cb->run(t, lc, cb->user_data);
|
|
cb->run(t, lc, cb->user_data);
|
|
- ff_mutex_lock(&e->lock);
|
|
|
|
|
|
+ if (e->thread_count > 0)
|
|
|
|
+ ff_mutex_lock(&e->lock);
|
|
return 1;
|
|
return 1;
|
|
}
|
|
}
|
|
return 0;
|
|
return 0;
|
|
@@ -146,14 +148,17 @@ AVExecutor* av_executor_alloc(const AVTaskCallbacks *cb, int thread_count)
|
|
return NULL;
|
|
return NULL;
|
|
e->cb = *cb;
|
|
e->cb = *cb;
|
|
|
|
|
|
- e->local_contexts = av_calloc(thread_count, e->cb.local_context_size);
|
|
|
|
|
|
+ e->local_contexts = av_calloc(FFMAX(thread_count, 1), e->cb.local_context_size);
|
|
if (!e->local_contexts)
|
|
if (!e->local_contexts)
|
|
goto free_executor;
|
|
goto free_executor;
|
|
|
|
|
|
- e->threads = av_calloc(thread_count, sizeof(*e->threads));
|
|
|
|
|
|
+ e->threads = av_calloc(FFMAX(thread_count, 1), sizeof(*e->threads));
|
|
if (!e->threads)
|
|
if (!e->threads)
|
|
goto free_executor;
|
|
goto free_executor;
|
|
|
|
|
|
|
|
+ if (!thread_count)
|
|
|
|
+ return e;
|
|
|
|
+
|
|
has_lock = !ff_mutex_init(&e->lock, NULL);
|
|
has_lock = !ff_mutex_init(&e->lock, NULL);
|
|
has_cond = !ff_cond_init(&e->cond, NULL);
|
|
has_cond = !ff_cond_init(&e->cond, NULL);
|
|
|
|
|
|
@@ -175,9 +180,12 @@ free_executor:
|
|
|
|
|
|
void av_executor_free(AVExecutor **executor)
|
|
void av_executor_free(AVExecutor **executor)
|
|
{
|
|
{
|
|
|
|
+ int thread_count;
|
|
|
|
+
|
|
if (!executor || !*executor)
|
|
if (!executor || !*executor)
|
|
return;
|
|
return;
|
|
- executor_free(*executor, 1, 1);
|
|
|
|
|
|
+ thread_count = (*executor)->thread_count;
|
|
|
|
+ executor_free(*executor, thread_count, thread_count);
|
|
*executor = NULL;
|
|
*executor = NULL;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -195,9 +203,9 @@ void av_executor_execute(AVExecutor *e, AVTask *t)
|
|
ff_cond_signal(&e->cond);
|
|
ff_cond_signal(&e->cond);
|
|
ff_mutex_unlock(&e->lock);
|
|
ff_mutex_unlock(&e->lock);
|
|
|
|
|
|
-#if !HAVE_THREADS
|
|
|
|
- // We are running in a single-threaded environment, so we must handle all tasks ourselves
|
|
|
|
- while (run_one_task(e, e->local_contexts))
|
|
|
|
- /* nothing */;
|
|
|
|
-#endif
|
|
|
|
|
|
+ if (!e->thread_count || !HAVE_THREADS) {
|
|
|
|
+ // We are running in a single-threaded environment, so we must handle all tasks ourselves
|
|
|
|
+ while (run_one_task(e, e->local_contexts))
|
|
|
|
+ /* nothing */;
|
|
|
|
+ }
|
|
}
|
|
}
|