Add TASK_CTL_FIND

This commit is contained in:
twinaphex 2016-01-28 09:57:55 +01:00
parent a5e8615091
commit d61eb7a8db
4 changed files with 29 additions and 15 deletions

View File

@ -225,6 +225,7 @@ bool rarch_task_push_decompress(
rarch_task_callback_t cb, rarch_task_callback_t cb,
void *user_data) void *user_data)
{ {
task_finder_data_t find_data;
char tmp[PATH_MAX_LENGTH]; char tmp[PATH_MAX_LENGTH];
decompress_state_t *s = NULL; decompress_state_t *s = NULL;
rarch_task_t *t = NULL; rarch_task_t *t = NULL;
@ -250,7 +251,10 @@ bool rarch_task_push_decompress(
if (!valid_ext || !valid_ext[0]) if (!valid_ext || !valid_ext[0])
valid_ext = NULL; 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); RARCH_LOG("[decompress] File '%s' already being decompressed.\n", source_file);
return false; return false;

View File

@ -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) 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]; char tmp[PATH_MAX_LENGTH];
task_finder_data_t find_data;
struct http_connection_t *conn = NULL; struct http_connection_t *conn = NULL;
rarch_task_t *t = NULL; rarch_task_t *t = NULL;
http_handle_t *http = 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)) if (string_is_empty(url))
return false; return false;
find_data.func = rarch_task_http_finder;
find_data.userdata = (void*)url;
/* Concurrent download of the same file is not allowed */ /* 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); RARCH_LOG("[http] '%s'' is already being downloaded.\n", url);
return false; return false;

View File

@ -369,11 +369,6 @@ static struct rarch_task_impl impl_threaded = {
}; };
#endif #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) bool task_ctl(enum task_ctl_state state, void *data)
{ {
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
@ -399,6 +394,13 @@ bool task_ctl(enum task_ctl_state state, void *data)
impl_current->init(); impl_current->init();
break; 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: case TASK_CTL_CHECK:
{ {
#ifdef HAVE_THREADS #ifdef HAVE_THREADS

View File

@ -44,6 +44,12 @@ enum task_ctl_state
* This must only be called from the main thread. */ * This must only be called from the main thread. */
TASK_CTL_INIT, 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. /* Blocks until all tasks have finished.
* This must only be called from the main thread. */ * This must only be called from the main thread. */
TASK_CTL_WAIT, TASK_CTL_WAIT,
@ -107,14 +113,12 @@ struct rarch_task
rarch_task_t *next; rarch_task_t *next;
}; };
/** typedef struct task_finder_data
* @brief Calls func for every running task until it returns true. {
* rarch_task_finder_t func;
* @param func void *userdata;
* @param user_data } task_finder_data_t;
* @return a task or NULL if not found.
*/
bool rarch_task_find(rarch_task_finder_t func, void *user_data);
#ifdef HAVE_NETWORKING #ifdef HAVE_NETWORKING
typedef struct { typedef struct {