diff --git a/tasks/task_decompress.c b/tasks/task_decompress.c index 6482c7dda1..59cfc91253 100644 --- a/tasks/task_decompress.c +++ b/tasks/task_decompress.c @@ -225,6 +225,7 @@ bool rarch_task_push_decompress( rarch_task_callback_t cb, void *user_data) { + task_finder_data_t find_data; char tmp[PATH_MAX_LENGTH]; decompress_state_t *s = NULL; rarch_task_t *t = NULL; @@ -250,7 +251,10 @@ bool rarch_task_push_decompress( if (!valid_ext || !valid_ext[0]) valid_ext = NULL; - if (rarch_task_find(rarch_task_decompress_finder, (void*)source_file)) + find_data.func = rarch_task_decompress_finder; + find_data.userdata = (void*)source_file; + + if (task_ctl(TASK_CTL_FIND, &find_data)) { RARCH_LOG("[decompress] File '%s' already being decompressed.\n", source_file); return false; diff --git a/tasks/task_http.c b/tasks/task_http.c index 724acf59e0..5c2b3564e9 100644 --- a/tasks/task_http.c +++ b/tasks/task_http.c @@ -207,6 +207,7 @@ static bool rarch_task_http_finder(rarch_task_t *task, void *user_data) bool rarch_task_push_http_transfer(const char *url, const char *type, rarch_task_callback_t cb, void *user_data) { char tmp[PATH_MAX_LENGTH]; + task_finder_data_t find_data; struct http_connection_t *conn = NULL; rarch_task_t *t = NULL; http_handle_t *http = NULL; @@ -214,8 +215,11 @@ bool rarch_task_push_http_transfer(const char *url, const char *type, rarch_task if (string_is_empty(url)) return false; + find_data.func = rarch_task_http_finder; + find_data.userdata = (void*)url; + /* Concurrent download of the same file is not allowed */ - if (rarch_task_find(rarch_task_http_finder, (void*)url)) + if (task_ctl(TASK_CTL_FIND, &find_data)) { RARCH_LOG("[http] '%s'' is already being downloaded.\n", url); return false; diff --git a/tasks/tasks.c b/tasks/tasks.c index 3839697b20..9d9f09ca71 100644 --- a/tasks/tasks.c +++ b/tasks/tasks.c @@ -369,11 +369,6 @@ static struct rarch_task_impl impl_threaded = { }; #endif -bool rarch_task_find(rarch_task_finder_t func, void *user_data) -{ - return impl_current->find(func, user_data); -} - bool task_ctl(enum task_ctl_state state, void *data) { #ifdef HAVE_THREADS @@ -399,6 +394,13 @@ bool task_ctl(enum task_ctl_state state, void *data) impl_current->init(); break; + case TASK_CTL_FIND: + { + task_finder_data_t *find_data = (task_finder_data_t*)data; + if (!impl_current->find(find_data->func, find_data->userdata)) + return false; + } + break; case TASK_CTL_CHECK: { #ifdef HAVE_THREADS diff --git a/tasks/tasks.h b/tasks/tasks.h index a76d0e3ccf..d4bccdbec5 100644 --- a/tasks/tasks.h +++ b/tasks/tasks.h @@ -44,6 +44,12 @@ enum task_ctl_state * This must only be called from the main thread. */ TASK_CTL_INIT, + /** + * Calls func for every running task until it returns true. + * Returns a task or NULL if not found. + */ + TASK_CTL_FIND, + /* Blocks until all tasks have finished. * This must only be called from the main thread. */ TASK_CTL_WAIT, @@ -107,14 +113,12 @@ struct rarch_task rarch_task_t *next; }; -/** - * @brief Calls func for every running task until it returns true. - * - * @param func - * @param user_data - * @return a task or NULL if not found. - */ -bool rarch_task_find(rarch_task_finder_t func, void *user_data); +typedef struct task_finder_data +{ + rarch_task_finder_t func; + void *userdata; +} task_finder_data_t; + #ifdef HAVE_NETWORKING typedef struct {