2015-05-05 17:36:58 +02:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2016-02-09 17:12:39 +01:00
|
|
|
* Copyright (C) 2011-2016 - Higor Euripedes
|
2016-01-10 04:06:50 +01:00
|
|
|
* Copyright (C) 2011-2016 - Daniel De Matteis
|
2015-05-05 17:36:58 +02:00
|
|
|
*
|
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2016-02-09 17:55:15 +01:00
|
|
|
#ifndef TASK_QUEUE_H
|
|
|
|
#define TASK_QUEUE_H
|
2015-05-05 17:36:58 +02:00
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <boolean.h>
|
2015-07-08 22:14:31 +02:00
|
|
|
|
2015-05-05 17:36:58 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2016-02-09 17:51:51 +01:00
|
|
|
enum task_queue_ctl_state
|
2016-01-28 09:35:25 +01:00
|
|
|
{
|
2016-01-28 09:38:21 +01:00
|
|
|
TASK_CTL_NONE = 0,
|
|
|
|
|
2016-01-28 09:48:47 +01:00
|
|
|
/* Deinitializes the task system.
|
|
|
|
* This deinitializes the task system.
|
|
|
|
* The tasks that are running at
|
|
|
|
* the moment will stay on hold
|
|
|
|
* until TASK_CTL_INIT is called again. */
|
|
|
|
TASK_CTL_DEINIT,
|
|
|
|
|
2016-01-28 09:52:28 +01:00
|
|
|
/* Initializes the task system.
|
|
|
|
* This initializes the task system
|
|
|
|
* and chooses an appropriate
|
|
|
|
* implementation according to the settings.
|
|
|
|
*
|
|
|
|
* This must only be called from the main thread. */
|
|
|
|
TASK_CTL_INIT,
|
|
|
|
|
2016-01-28 09:57:55 +01:00
|
|
|
/**
|
2016-02-09 17:12:39 +01:00
|
|
|
* Calls func for every running task
|
|
|
|
* until it returns true.
|
2016-01-28 09:57:55 +01:00
|
|
|
* Returns a task or NULL if not found.
|
|
|
|
*/
|
|
|
|
TASK_CTL_FIND,
|
|
|
|
|
2016-01-28 09:38:21 +01:00
|
|
|
/* Blocks until all tasks have finished.
|
|
|
|
* This must only be called from the main thread. */
|
|
|
|
TASK_CTL_WAIT,
|
|
|
|
|
2016-01-28 09:45:14 +01:00
|
|
|
/* Checks for finished tasks
|
2016-02-09 17:12:39 +01:00
|
|
|
* Takes the finished tasks, if any,
|
|
|
|
* and runs their callbacks.
|
2016-01-28 09:45:14 +01:00
|
|
|
* This must only be called from the main thread. */
|
|
|
|
TASK_CTL_CHECK,
|
|
|
|
|
2016-01-28 09:42:55 +01:00
|
|
|
/* Pushes a task
|
|
|
|
* The task will start as soon as possible. */
|
|
|
|
TASK_CTL_PUSH,
|
|
|
|
|
2016-01-28 09:38:21 +01:00
|
|
|
/* Sends a signal to terminate all the tasks.
|
|
|
|
*
|
|
|
|
* This won't terminate the tasks immediately.
|
|
|
|
* They will finish as soon as possible.
|
|
|
|
*
|
|
|
|
* This must only be called from the main thread. */
|
2016-02-09 17:41:19 +01:00
|
|
|
TASK_CTL_RESET,
|
|
|
|
|
|
|
|
TASK_CTL_SET_THREADED,
|
|
|
|
|
|
|
|
TASK_CTL_UNSET_THREADED,
|
|
|
|
|
|
|
|
TASK_CTL_IS_THREADED
|
2016-01-28 09:35:25 +01:00
|
|
|
};
|
|
|
|
|
2016-02-09 17:47:04 +01:00
|
|
|
typedef struct retro_task retro_task_t;
|
|
|
|
typedef void (*retro_task_callback_t)(void *task_data,
|
2016-01-28 18:51:07 +01:00
|
|
|
void *user_data, const char *error);
|
2016-02-09 17:12:39 +01:00
|
|
|
|
2016-02-09 17:47:04 +01:00
|
|
|
typedef void (*retro_task_handler_t)(retro_task_t *task);
|
2016-02-09 17:12:39 +01:00
|
|
|
|
2016-02-09 17:47:04 +01:00
|
|
|
typedef bool (*retro_task_finder_t)(retro_task_t *task,
|
2016-02-09 17:12:39 +01:00
|
|
|
void *userdata);
|
2015-11-22 20:15:42 -03:00
|
|
|
|
2016-01-28 09:33:09 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
char *source_file;
|
|
|
|
} decompress_task_data_t;
|
|
|
|
|
2016-02-09 17:47:04 +01:00
|
|
|
struct retro_task
|
2016-01-28 09:33:09 +01:00
|
|
|
{
|
2016-02-09 17:47:04 +01:00
|
|
|
retro_task_handler_t handler;
|
2015-11-22 20:15:42 -03:00
|
|
|
|
2016-01-28 18:51:07 +01:00
|
|
|
/* always called from the main loop */
|
2016-02-09 17:47:04 +01:00
|
|
|
retro_task_callback_t callback;
|
2016-01-28 18:51:07 +01:00
|
|
|
|
|
|
|
/* set to true by the handler to signal
|
|
|
|
* the task has finished executing. */
|
2016-01-28 09:33:09 +01:00
|
|
|
bool finished;
|
2015-11-22 20:15:42 -03:00
|
|
|
|
2016-02-09 17:12:39 +01:00
|
|
|
/* set to true by the task system
|
|
|
|
* to signal the task *must* end. */
|
2016-01-28 09:33:09 +01:00
|
|
|
bool cancelled;
|
2015-11-24 21:50:29 -03:00
|
|
|
|
2016-01-28 09:33:09 +01:00
|
|
|
/* created by the handler, destroyed by the user */
|
|
|
|
void *task_data;
|
2015-11-22 20:15:42 -03:00
|
|
|
|
2016-01-28 09:33:09 +01:00
|
|
|
/* owned by the user */
|
|
|
|
void *user_data;
|
2015-11-22 20:15:42 -03:00
|
|
|
|
2016-01-28 09:33:09 +01:00
|
|
|
/* created and destroyed by the code related to the handler */
|
|
|
|
void *state;
|
2015-11-22 20:15:42 -03:00
|
|
|
|
2016-01-28 18:51:07 +01:00
|
|
|
/* created by task handler; destroyed by main loop
|
|
|
|
* (after calling the callback) */
|
2016-01-28 09:33:09 +01:00
|
|
|
char *error;
|
2015-11-22 20:15:42 -03:00
|
|
|
|
2016-01-28 09:33:09 +01:00
|
|
|
/* -1 = unmettered, 0-100 progress value */
|
|
|
|
int8_t progress;
|
2016-01-28 18:51:07 +01:00
|
|
|
|
2016-02-09 17:12:39 +01:00
|
|
|
/* handler can modify but will be
|
|
|
|
* free()d automatically if non-NULL. */
|
2016-01-28 18:51:07 +01:00
|
|
|
char *title;
|
2015-11-30 09:17:46 -03:00
|
|
|
|
2016-01-28 09:33:09 +01:00
|
|
|
/* don't touch this. */
|
2016-02-09 17:47:04 +01:00
|
|
|
retro_task_t *next;
|
2015-11-22 20:15:42 -03:00
|
|
|
};
|
|
|
|
|
2016-01-28 09:57:55 +01:00
|
|
|
typedef struct task_finder_data
|
|
|
|
{
|
2016-02-09 17:47:04 +01:00
|
|
|
retro_task_finder_t func;
|
2016-01-28 09:57:55 +01:00
|
|
|
void *userdata;
|
|
|
|
} task_finder_data_t;
|
|
|
|
|
2016-02-09 17:47:04 +01:00
|
|
|
void push_task_progress(retro_task_t *task);
|
2016-01-24 00:51:17 +01:00
|
|
|
|
2016-02-09 17:51:51 +01:00
|
|
|
bool task_queue_ctl(enum task_queue_ctl_state state, void *data);
|
2016-01-28 09:35:25 +01:00
|
|
|
|
2015-05-05 17:36:58 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|