RetroArch/libretro-common/queues/task_queue.c

825 lines
18 KiB
C
Raw Normal View History

2016-02-09 17:11:11 +00:00
/* Copyright (C) 2010-2016 The RetroArch team
2016-01-10 03:06:50 +00:00
*
2016-02-09 17:11:11 +00:00
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (task_queue.c).
* ---------------------------------------------------------------------------------------
2016-01-10 03:06:50 +00:00
*
2016-02-09 17:11:11 +00:00
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
2016-01-10 03:06:50 +00:00
*
2016-02-09 17:11:11 +00:00
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2016-01-10 03:06:50 +00:00
*/
#include <stdio.h>
2015-11-22 23:15:42 +00:00
#include <stdlib.h>
2015-11-30 22:24:11 +00:00
#include <stdarg.h>
2015-11-22 23:15:42 +00:00
2016-02-09 17:13:47 +00:00
#include <queues/task_queue.h>
2015-11-22 23:15:42 +00:00
#ifdef HAVE_THREADS
2016-01-30 03:46:41 +00:00
#include <rthreads/rthreads.h>
#define SLOCK_LOCK(x) slock_lock(x)
#define SLOCK_UNLOCK(x) slock_unlock(x)
#else
#define SLOCK_LOCK(x)
#define SLOCK_UNLOCK(x)
2015-11-22 23:15:42 +00:00
#endif
2016-01-28 08:48:47 +00:00
typedef struct
{
2016-02-09 16:47:04 +00:00
retro_task_t *front;
retro_task_t *back;
} task_queue_t;
2015-11-22 23:15:42 +00:00
2016-02-09 16:47:04 +00:00
struct retro_task_impl
2016-01-28 08:48:47 +00:00
{
retro_task_queue_msg_t msg_push;
2016-02-09 16:47:04 +00:00
void (*push_running)(retro_task_t *);
2016-05-05 18:32:36 +00:00
void (*cancel)(void *);
void (*reset)(void);
void (*wait)(void);
2015-11-22 23:15:42 +00:00
void (*gather)(void);
2016-02-09 16:47:04 +00:00
bool (*find)(retro_task_finder_t, void*);
void (*retrieve)(task_retriever_data_t *data);
2015-11-22 23:15:42 +00:00
void (*init)(void);
void (*deinit)(void);
};
2016-01-28 08:48:47 +00:00
static task_queue_t tasks_running = {NULL, NULL};
static task_queue_t tasks_finished = {NULL, NULL};
2015-11-22 23:15:42 +00:00
static struct retro_task_impl *impl_current = NULL;
static bool task_threaded_enable = false;
static void task_queue_msg_push(retro_task_t *task,
unsigned prio, unsigned duration,
2016-02-09 17:11:11 +00:00
bool flush, const char *fmt, ...)
{
char buf[1024];
va_list ap;
2016-10-02 20:35:27 +00:00
2016-10-09 07:56:03 +00:00
buf[0] = '\0';
2016-02-09 17:11:11 +00:00
va_start(ap, fmt);
vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
if (impl_current->msg_push)
impl_current->msg_push(buf, prio, duration, flush);
2016-02-09 17:11:11 +00:00
}
static void task_queue_push_progress(retro_task_t *task)
2016-02-09 17:11:11 +00:00
{
2016-06-28 20:02:01 +00:00
if (task->title && !task->mute)
2016-02-09 17:11:11 +00:00
{
if (task->finished)
{
if (task->error)
task_queue_msg_push(task, 1, 60, true, "%s: %s",
2016-10-29 14:53:57 +00:00
"Task failed", task->title);
2016-02-09 17:11:11 +00:00
else
task_queue_msg_push(task, 1, 60, false, "100%%: %s", task->title);
2016-02-09 17:11:11 +00:00
}
else
{
if (task->progress >= 0 && task->progress <= 100)
task_queue_msg_push(task, 1, 60, false, "%i%%: %s",
2016-02-09 17:11:11 +00:00
task->progress, task->title);
else
task_queue_msg_push(task, 1, 60, false, "%s...", task->title);
2016-02-09 17:11:11 +00:00
}
}
}
2016-02-09 16:47:04 +00:00
static void task_queue_put(task_queue_t *queue, retro_task_t *task)
2015-11-22 23:15:42 +00:00
{
task->next = NULL;
2015-11-22 23:15:42 +00:00
2016-01-28 08:48:47 +00:00
if (queue->front)
queue->back->next = task;
2016-01-28 08:48:47 +00:00
else
queue->front = task;
2015-11-22 23:15:42 +00:00
queue->back = task;
2015-11-22 23:15:42 +00:00
}
2016-02-09 16:47:04 +00:00
static retro_task_t *task_queue_get(task_queue_t *queue)
2015-11-22 23:15:42 +00:00
{
2016-02-09 16:47:04 +00:00
retro_task_t *task = queue->front;
2015-11-22 23:15:42 +00:00
if (task)
{
queue->front = task->next;
task->next = NULL;
}
2015-11-22 23:15:42 +00:00
return task;
}
2016-02-09 16:47:04 +00:00
static void retro_task_internal_gather(void)
{
2016-02-09 16:47:04 +00:00
retro_task_t *task = NULL;
while ((task = task_queue_get(&tasks_finished)) != NULL)
{
2016-02-09 16:56:36 +00:00
task_queue_push_progress(task);
if (task->callback)
task->callback(task->task_data, task->user_data, task->error);
if (task->cleanup)
task->cleanup(task);
if (task->error)
free(task->error);
if (task->title)
free(task->title);
free(task);
}
}
2016-02-09 17:00:17 +00:00
static void retro_task_regular_push_running(retro_task_t *task)
2015-11-22 23:15:42 +00:00
{
task_queue_put(&tasks_running, task);
2015-11-22 23:15:42 +00:00
}
2016-05-05 18:32:36 +00:00
static void retro_task_regular_cancel(void *task)
{
2016-05-08 02:04:50 +00:00
retro_task_t *t = (retro_task_t*)task;
t->cancelled = true;
2016-05-05 18:32:36 +00:00
}
2016-10-02 20:35:27 +00:00
2016-02-09 17:00:17 +00:00
static void retro_task_regular_gather(void)
2015-11-22 23:15:42 +00:00
{
2016-02-09 16:47:04 +00:00
retro_task_t *task = NULL;
retro_task_t *queue = NULL;
retro_task_t *next = NULL;
2015-11-22 23:15:42 +00:00
while ((task = task_queue_get(&tasks_running)) != NULL)
2015-11-22 23:15:42 +00:00
{
task->next = queue;
queue = task;
}
for (task = queue; task; task = next)
2015-11-22 23:15:42 +00:00
{
next = task->next;
2015-11-22 23:15:42 +00:00
task->handler(task);
2016-02-09 16:56:36 +00:00
task_queue_push_progress(task);
2015-11-22 23:15:42 +00:00
if (task->finished)
task_queue_put(&tasks_finished, task);
2015-11-22 23:15:42 +00:00
else
2016-02-09 17:00:17 +00:00
retro_task_regular_push_running(task);
2015-11-22 23:15:42 +00:00
}
2016-02-09 16:47:04 +00:00
retro_task_internal_gather();
2015-11-22 23:15:42 +00:00
}
2016-02-09 17:00:17 +00:00
static void retro_task_regular_wait(void)
{
while (tasks_running.front)
2016-02-09 17:00:17 +00:00
retro_task_regular_gather();
}
2016-02-09 17:00:17 +00:00
static void retro_task_regular_reset(void)
{
2016-02-09 16:47:04 +00:00
retro_task_t *task = tasks_running.front;
2016-02-09 16:27:29 +00:00
for (; task; task = task->next)
task->cancelled = true;
}
2016-02-09 17:00:17 +00:00
static void retro_task_regular_init(void)
2015-11-22 23:15:42 +00:00
{
}
2016-02-09 17:00:17 +00:00
static void retro_task_regular_deinit(void)
2015-11-22 23:15:42 +00:00
{
}
2016-02-09 17:00:17 +00:00
static bool retro_task_regular_find(retro_task_finder_t func, void *user_data)
{
2016-02-09 16:47:04 +00:00
retro_task_t *task = tasks_running.front;
2016-02-09 16:27:29 +00:00
for (; task; task = task->next)
{
if (func(task, user_data))
return true;
}
return false;
}
static void retro_task_regular_retrieve(task_retriever_data_t *data)
{
2016-06-01 00:37:26 +00:00
retro_task_t *task = NULL;
task_retriever_info_t *tail = NULL;
/* Parse all running tasks and handle matching handlers */
for (task = tasks_running.front; task != NULL; task = task->next)
2016-06-01 00:37:26 +00:00
{
task_retriever_info_t *info = NULL;
if (task->handler != data->handler)
continue;
2016-06-01 00:37:26 +00:00
/* Create new link */
info = (task_retriever_info_t*)malloc(sizeof(task_retriever_info_t));
info->data = malloc(data->element_size);
info->next = NULL;
2016-06-01 00:37:26 +00:00
/* Call retriever function and fill info-specific data */
if (!data->func(task, info->data))
{
free(info->data);
free(info);
continue;
}
/* Add link to list */
if (data->list)
{
if (tail)
{
2016-06-01 00:37:26 +00:00
tail->next = info;
2016-09-25 13:25:20 +00:00
tail = tail->next;
}
2016-09-25 13:25:20 +00:00
else
tail = info;
}
2016-06-01 00:37:26 +00:00
else
{
2016-09-25 13:25:20 +00:00
data->list = info;
tail = data->list;
2016-06-01 00:37:26 +00:00
}
}
}
2016-02-09 16:47:04 +00:00
static struct retro_task_impl impl_regular = {
NULL,
2016-02-09 17:00:17 +00:00
retro_task_regular_push_running,
2016-05-05 18:32:36 +00:00
retro_task_regular_cancel,
2016-02-09 17:00:17 +00:00
retro_task_regular_reset,
retro_task_regular_wait,
retro_task_regular_gather,
retro_task_regular_find,
retro_task_regular_retrieve,
2016-02-09 17:00:17 +00:00
retro_task_regular_init,
retro_task_regular_deinit
2015-11-22 23:15:42 +00:00
};
#ifdef HAVE_THREADS
2016-02-09 16:01:07 +00:00
static slock_t *running_lock = NULL;
static slock_t *finished_lock = NULL;
static slock_t *property_lock = NULL;
static slock_t *queue_lock = NULL;
2016-02-09 16:01:07 +00:00
static scond_t *worker_cond = NULL;
2015-11-22 23:15:42 +00:00
static sthread_t *worker_thread = NULL;
2016-02-09 16:01:07 +00:00
static bool worker_continue = true; /* use running_lock when touching it */
2015-11-22 23:15:42 +00:00
2016-05-08 14:25:26 +00:00
static void task_queue_remove(task_queue_t *queue, retro_task_t *task)
{
2016-12-30 02:32:35 +00:00
retro_task_t *t = NULL;
retro_task_t *front = NULL;
slock_lock(queue_lock);
front = queue->front;
slock_unlock(queue_lock);
2016-05-08 14:25:26 +00:00
/* Remove first element if needed */
if (task == front)
2016-05-08 14:25:26 +00:00
{
slock_lock(queue_lock);
2016-05-08 14:25:26 +00:00
queue->front = task->next;
slock_unlock(queue_lock);
2016-05-08 14:25:26 +00:00
task->next = NULL;
2016-12-30 02:32:35 +00:00
2016-05-08 14:25:26 +00:00
return;
}
/* Parse queue */
t = front;
2016-12-30 02:32:35 +00:00
2016-05-08 14:25:26 +00:00
while (t && t->next)
{
/* Remove task and update queue */
if (t->next == task)
{
t->next = task->next;
task->next = NULL;
break;
}
/* Update iterator */
t = t->next;
}
}
2016-02-09 17:00:17 +00:00
static void retro_task_threaded_push_running(retro_task_t *task)
2015-11-22 23:15:42 +00:00
{
slock_lock(running_lock);
2016-12-30 04:39:40 +00:00
slock_lock(queue_lock);
task_queue_put(&tasks_running, task);
2015-11-22 23:15:42 +00:00
scond_signal(worker_cond);
2016-12-30 04:39:40 +00:00
slock_unlock(queue_lock);
2015-11-22 23:15:42 +00:00
slock_unlock(running_lock);
}
2016-05-05 18:32:36 +00:00
static void retro_task_threaded_cancel(void *task)
{
retro_task_t *t;
slock_lock(running_lock);
2016-10-02 20:35:27 +00:00
2016-05-05 18:32:36 +00:00
for (t = tasks_running.front; t; t = t->next)
{
if (t == task)
{
t->cancelled = true;
break;
}
}
slock_unlock(running_lock);
}
2016-02-09 17:00:17 +00:00
static void retro_task_threaded_gather(void)
2015-11-22 23:15:42 +00:00
{
2016-02-09 16:47:04 +00:00
retro_task_t *task = NULL;
2016-01-24 00:30:19 +00:00
slock_lock(property_lock);
slock_lock(running_lock);
for (task = tasks_running.front; task; task = task->next)
2016-02-09 16:56:36 +00:00
task_queue_push_progress(task);
slock_unlock(running_lock);
2015-11-22 23:15:42 +00:00
slock_lock(finished_lock);
2016-02-09 16:47:04 +00:00
retro_task_internal_gather();
2015-11-22 23:15:42 +00:00
slock_unlock(finished_lock);
slock_unlock(property_lock);
2015-11-22 23:15:42 +00:00
}
2016-02-09 17:00:17 +00:00
static void retro_task_threaded_wait(void)
{
2016-01-24 00:30:19 +00:00
bool wait = false;
do
{
2016-02-09 17:00:17 +00:00
retro_task_threaded_gather();
slock_lock(running_lock);
wait = (tasks_running.front != NULL);
slock_unlock(running_lock);
} while (wait);
}
2016-02-09 17:00:17 +00:00
static void retro_task_threaded_reset(void)
{
2016-02-09 16:47:04 +00:00
retro_task_t *task = NULL;
slock_lock(running_lock);
for (task = tasks_running.front; task; task = task->next)
task->cancelled = true;
slock_unlock(running_lock);
}
2016-02-09 17:00:17 +00:00
static bool retro_task_threaded_find(
retro_task_finder_t func, void *user_data)
{
retro_task_t *task = NULL;
bool result = false;
2016-02-09 17:00:17 +00:00
slock_lock(running_lock);
for (task = tasks_running.front; task; task = task->next)
{
if (func(task, user_data))
{
result = true;
break;
}
2016-02-09 17:00:17 +00:00
}
slock_unlock(running_lock);
return result;
2016-02-09 17:00:17 +00:00
}
static void retro_task_threaded_retrieve(task_retriever_data_t *data)
{
/* Protect access to running tasks */
slock_lock(running_lock);
/* Call regular retrieve function */
retro_task_regular_retrieve(data);
/* Release access to running tasks */
slock_unlock(running_lock);
}
2015-11-22 23:15:42 +00:00
static void threaded_worker(void *userdata)
{
(void)userdata;
for (;;)
{
2016-02-09 16:47:04 +00:00
retro_task_t *task = NULL;
bool finished = false;
2015-11-22 23:15:42 +00:00
if (!worker_continue)
break; /* should we keep running until all tasks finished? */
slock_lock(running_lock);
2015-11-22 23:15:42 +00:00
/* Get first task to run */
task = tasks_running.front;
if (task == NULL)
2015-11-22 23:15:42 +00:00
{
scond_wait(worker_cond, running_lock);
slock_unlock(running_lock);
continue;
}
slock_unlock(running_lock);
task->handler(task);
slock_lock(property_lock);
finished = task->finished;
slock_unlock(property_lock);
slock_lock(running_lock);
task_queue_remove(&tasks_running, task);
slock_unlock(running_lock);
/* Update queue */
if (!finished)
2015-11-22 23:15:42 +00:00
{
/* Re-add task to running queue */
retro_task_threaded_push_running(task);
}
else
{
/* Add task to finished queue */
slock_lock(finished_lock);
task_queue_put(&tasks_finished, task);
slock_unlock(finished_lock);
2015-11-22 23:15:42 +00:00
}
}
}
2016-02-09 17:00:17 +00:00
static void retro_task_threaded_init(void)
2015-11-22 23:15:42 +00:00
{
running_lock = slock_new();
finished_lock = slock_new();
property_lock = slock_new();
queue_lock = slock_new();
2015-11-22 23:15:42 +00:00
worker_cond = scond_new();
slock_lock(running_lock);
worker_continue = true;
slock_unlock(running_lock);
worker_thread = sthread_create(threaded_worker, NULL);
}
2016-02-09 17:00:17 +00:00
static void retro_task_threaded_deinit(void)
2015-11-22 23:15:42 +00:00
{
slock_lock(running_lock);
worker_continue = false;
scond_signal(worker_cond);
slock_unlock(running_lock);
sthread_join(worker_thread);
scond_free(worker_cond);
slock_free(running_lock);
slock_free(finished_lock);
slock_free(property_lock);
slock_free(queue_lock);
2015-11-22 23:15:42 +00:00
worker_thread = NULL;
worker_cond = NULL;
running_lock = NULL;
finished_lock = NULL;
property_lock = NULL;
queue_lock = NULL;
2015-11-22 23:15:42 +00:00
}
2016-02-09 16:47:04 +00:00
static struct retro_task_impl impl_threaded = {
NULL,
2016-02-09 17:00:17 +00:00
retro_task_threaded_push_running,
2016-05-05 18:32:36 +00:00
retro_task_threaded_cancel,
2016-02-09 17:00:17 +00:00
retro_task_threaded_reset,
retro_task_threaded_wait,
retro_task_threaded_gather,
retro_task_threaded_find,
retro_task_threaded_retrieve,
2016-02-09 17:00:17 +00:00
retro_task_threaded_init,
retro_task_threaded_deinit
2015-11-22 23:15:42 +00:00
};
#endif
/* Deinitializes the task system.
* This deinitializes the task system.
* The tasks that are running at
* the moment will stay on hold */
void task_queue_deinit(void)
2016-01-28 08:35:25 +00:00
{
if (impl_current)
impl_current->deinit();
impl_current = NULL;
}
2016-01-28 08:52:28 +00:00
void task_queue_init(bool threaded, retro_task_queue_msg_t msg_push)
{
impl_current = &impl_regular;
2016-01-28 08:52:28 +00:00
#ifdef HAVE_THREADS
if (threaded)
{
task_threaded_enable = true;
impl_current = &impl_threaded;
}
2016-01-28 08:52:28 +00:00
#endif
impl_current->msg_push = msg_push;
impl_current->init();
}
void task_queue_set_threaded(void)
{
task_threaded_enable = true;
}
void task_queue_unset_threaded(void)
{
task_threaded_enable = false;
}
bool task_queue_is_threaded(void)
{
return task_threaded_enable;
}
bool task_queue_ctl(enum task_queue_ctl_state state, void *data)
{
switch (state)
{
2016-02-09 17:26:27 +00:00
case TASK_QUEUE_CTL_FIND:
2016-01-28 08:57:55 +00:00
{
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_QUEUE_CTL_RETRIEVE:
2016-05-08 02:04:50 +00:00
impl_current->retrieve((task_retriever_data_t*)data);
break;
2016-02-09 17:26:27 +00:00
case TASK_QUEUE_CTL_CHECK:
2016-01-28 08:45:14 +00:00
{
#ifdef HAVE_THREADS
bool current_threaded = (impl_current == &impl_threaded);
bool want_threaded = task_queue_is_threaded();
2016-01-28 08:45:14 +00:00
if (want_threaded != current_threaded)
task_queue_deinit();
2016-01-28 08:45:14 +00:00
if (!impl_current)
task_queue_init(want_threaded, impl_current->msg_push);
2016-01-28 08:45:14 +00:00
#endif
impl_current->gather();
}
break;
2016-02-09 17:26:27 +00:00
case TASK_QUEUE_CTL_PUSH:
2016-01-28 08:42:55 +00:00
{
retro_task_t *task = (retro_task_t*)data;
/* Ignore this task if a related one is already running */
if (task->type == TASK_TYPE_BLOCKING)
{
retro_task_t *running = NULL;
bool found = false;
SLOCK_LOCK(queue_lock);
running = tasks_running.front;
for (; running; running = running->next)
{
if (running->type == TASK_TYPE_BLOCKING)
{
found = true;
break;
}
}
2016-12-30 04:16:00 +00:00
SLOCK_UNLOCK(queue_lock);
/* skip this task, user must try again later */
if (found)
break;
}
2016-10-02 20:35:27 +00:00
/* The lack of NULL checks in the following functions
* is proposital to ensure correct control flow by the users. */
2016-01-28 08:42:55 +00:00
impl_current->push_running(task);
break;
}
2016-02-09 17:26:27 +00:00
case TASK_QUEUE_CTL_RESET:
2016-01-28 08:38:21 +00:00
impl_current->reset();
break;
2016-02-09 17:26:27 +00:00
case TASK_QUEUE_CTL_WAIT:
2016-01-28 08:38:21 +00:00
impl_current->wait();
break;
2016-02-09 17:26:27 +00:00
case TASK_QUEUE_CTL_NONE:
2016-01-28 08:35:25 +00:00
default:
break;
}
return true;
}
2016-05-05 18:32:36 +00:00
/**
* Signals a task to end without waiting for
* it to complete. */
2016-05-05 18:32:36 +00:00
void task_queue_cancel_task(void *task)
{
impl_current->cancel(task);
2016-05-05 18:32:36 +00:00
}
void *task_queue_retriever_info_next(task_retriever_info_t **link)
{
void *data = NULL;
/* Grab data and move to next link */
if (*link)
{
data = (*link)->data;
*link = (*link)->next;
}
return data;
}
void task_queue_retriever_info_free(task_retriever_info_t *list)
{
task_retriever_info_t *info;
/* Free links including retriever-specific data */
while (list)
{
info = list->next;
free(list->data);
free(list);
list = info;
}
}
void task_set_finished(retro_task_t *task, bool finished)
{
SLOCK_LOCK(property_lock);
task->finished = finished;
SLOCK_UNLOCK(property_lock);
}
void task_set_mute(retro_task_t *task, bool mute)
{
SLOCK_LOCK(property_lock);
task->mute = mute;
SLOCK_UNLOCK(property_lock);
}
void task_set_error(retro_task_t *task, char *error)
{
SLOCK_LOCK(property_lock);
task->error = error;
SLOCK_UNLOCK(property_lock);
}
void task_set_progress(retro_task_t *task, int8_t progress)
{
SLOCK_LOCK(property_lock);
task->progress = progress;
SLOCK_UNLOCK(property_lock);
}
void task_set_title(retro_task_t *task, char *title)
{
SLOCK_LOCK(property_lock);
task->title = title;
SLOCK_UNLOCK(property_lock);
}
void task_set_data(retro_task_t *task, void *data)
{
SLOCK_LOCK(running_lock);
task->task_data = data;
SLOCK_UNLOCK(running_lock);
}
void task_set_cancelled(retro_task_t *task, bool cancelled)
{
SLOCK_LOCK(running_lock);
task->cancelled = cancelled;
SLOCK_UNLOCK(running_lock);
}
void task_free_title(retro_task_t *task)
{
SLOCK_LOCK(property_lock);
if (task->title)
free(task->title);
task->title = NULL;
SLOCK_UNLOCK(property_lock);
}
void* task_get_data(retro_task_t *task)
{
void *data = NULL;
SLOCK_LOCK(running_lock);
data = task->task_data;
SLOCK_UNLOCK(running_lock);
return data;
}
bool task_get_cancelled(retro_task_t *task)
{
bool cancelled = false;
SLOCK_LOCK(running_lock);
cancelled = task->cancelled;
SLOCK_UNLOCK(running_lock);
return cancelled;
}
bool task_get_finished(retro_task_t *task)
{
bool finished = false;
SLOCK_LOCK(property_lock);
finished = task->finished;
SLOCK_UNLOCK(property_lock);
return finished;
}
bool task_get_mute(retro_task_t *task)
{
bool mute = false;
SLOCK_LOCK(property_lock);
mute = task->mute;
SLOCK_UNLOCK(property_lock);
return mute;
}
char* task_get_error(retro_task_t *task)
{
char *error = NULL;
SLOCK_LOCK(property_lock);
error = task->error;
SLOCK_UNLOCK(property_lock);
return error;
}
int8_t task_get_progress(retro_task_t *task)
{
int8_t progress = 0;
SLOCK_LOCK(property_lock);
progress = task->progress;
SLOCK_UNLOCK(property_lock);
return progress;
}
char* task_get_title(retro_task_t *task)
{
char *title = NULL;
SLOCK_LOCK(property_lock);
title = task->title;
SLOCK_UNLOCK(property_lock);
return title;
}