Only use threads when the number > 1

This commit is contained in:
Francisco José García García 2020-01-04 16:36:26 +01:00
parent f92a507a9b
commit f559e931cf
1 changed files with 57 additions and 48 deletions

View File

@ -237,6 +237,7 @@ static bool create_softfilter_graph(rarch_softfilter_t *filt,
} }
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
if(filt->threads>1){
filt->thread_data = (struct filter_thread_data*) filt->thread_data = (struct filter_thread_data*)
calloc(threads, sizeof(*filt->thread_data)); calloc(threads, sizeof(*filt->thread_data));
if (!filt->thread_data) if (!filt->thread_data)
@ -258,6 +259,7 @@ static bool create_softfilter_graph(rarch_softfilter_t *filt,
if (!filt->thread_data[i].thread) if (!filt->thread_data[i].thread)
return false; return false;
} }
}
#endif #endif
return true; return true;
@ -475,6 +477,7 @@ void rarch_softfilter_free(rarch_softfilter_t *filt)
#endif #endif
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
if(filt->threads>1){
for (i = 0; i < filt->threads; i++) for (i = 0; i < filt->threads; i++)
{ {
if (!filt->thread_data[i].thread) if (!filt->thread_data[i].thread)
@ -488,6 +491,7 @@ void rarch_softfilter_free(rarch_softfilter_t *filt)
scond_free(filt->thread_data[i].cond); scond_free(filt->thread_data[i].cond);
} }
free(filt->thread_data); free(filt->thread_data);
}
#endif #endif
if (filt->conf) if (filt->conf)
@ -533,6 +537,7 @@ void rarch_softfilter_process(rarch_softfilter_t *filt,
output, output_stride, input, width, height, input_stride); output, output_stride, input, width, height, input_stride);
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
if(filt->threads>1){
/* Fire off workers */ /* Fire off workers */
for (i = 0; i < filt->threads; i++) for (i = 0; i < filt->threads; i++)
{ {
@ -557,6 +562,10 @@ void rarch_softfilter_process(rarch_softfilter_t *filt,
scond_wait(filt->thread_data[i].cond, filt->thread_data[i].lock); scond_wait(filt->thread_data[i].cond, filt->thread_data[i].lock);
slock_unlock(filt->thread_data[i].lock); slock_unlock(filt->thread_data[i].lock);
} }
} else {
for (i = 0; i < filt->threads; i++)
filt->packets[i].work(filt->impl_data, filt->packets[i].thread_data);
}
#else #else
for (i = 0; i < filt->threads; i++) for (i = 0; i < filt->threads; i++)
filt->packets[i].work(filt->impl_data, filt->packets[i].thread_data); filt->packets[i].work(filt->impl_data, filt->packets[i].thread_data);