RetroArch
task_queue.h
Go to the documentation of this file.
1 /* Copyright (C) 2010-2018 The RetroArch team
2  *
3  * ---------------------------------------------------------------------------------------
4  * The following license statement only applies to this file (task_queue.h).
5  * ---------------------------------------------------------------------------------------
6  *
7  * Permission is hereby granted, free of charge,
8  * to any person obtaining a copy of this software and associated documentation files (the "Software"),
9  * to deal in the Software without restriction, including without limitation the rights to
10  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
11  * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  */
22 
23 #ifndef __LIBRETRO_SDK_TASK_QUEUE_H__
24 #define __LIBRETRO_SDK_TASK_QUEUE_H__
25 
26 #include <stdint.h>
27 #include <stddef.h>
28 #include <boolean.h>
29 
30 #include <retro_common.h>
31 #include <retro_common_api.h>
32 
34 
36 {
38  /* Only one blocking task can exist in the queue at a time.
39  * Attempts to add a new one while another is running is
40  * ignored.
41  */
43 };
44 
45 
46 typedef struct retro_task retro_task_t;
48  void *user_data, const char *error);
49 
51 
53  void *userdata);
54 
55 typedef void (*retro_task_queue_msg_t)(const char *msg,
56  unsigned prio, unsigned duration, bool flush);
57 
58 typedef bool (*retro_task_retriever_t)(retro_task_t *task, void *data);
59 
61 
62 typedef struct
63 {
64  char *source_file;
66 
67 struct retro_task
68 {
70 
71  /* always called from the main loop */
73 
74  /* task cleanup handler to free allocated resources, will
75  * be called immediately after running the main callback */
77 
78  /* set to true by the handler to signal
79  * the task has finished executing. */
80  bool finished;
81 
82  /* set to true by the task system
83  * to signal the task *must* end. */
84  bool cancelled;
85 
86  /* if true no OSD messages will be displayed. */
87  bool mute;
88 
89  /* created by the handler, destroyed by the user */
90  void *task_data;
91 
92  /* owned by the user */
93  void *user_data;
94 
95  /* created and destroyed by the code related to the handler */
96  void *state;
97 
98  /* created by task handler; destroyed by main loop
99  * (after calling the callback) */
100  char *error;
101 
102  /* -1 = unmetered/indeterminate, 0-100 = current progress percentage */
104 
106 
107  /* handler can modify but will be
108  * free()d automatically if non-NULL. */
109  char *title;
110 
112 
113  /* don't touch this. */
115 };
116 
117 typedef struct task_finder_data
118 {
120  void *userdata;
122 
123 typedef struct task_retriever_info
124 {
126  void *data;
128 
129 typedef struct task_retriever_data
130 {
132  size_t element_size;
136 
138 
140 
144 void task_queue_cancel_task(void *task);
145 
146 void task_set_finished(retro_task_t *task, bool finished);
147 
148 void task_set_mute(retro_task_t *task, bool mute);
149 
150 void task_set_error(retro_task_t *task, char *error);
151 
152 void task_set_progress(retro_task_t *task, int8_t progress);
153 
154 void task_set_title(retro_task_t *task, char *title);
155 
156 void task_set_data(retro_task_t *task, void *data);
157 
158 void task_set_cancelled(retro_task_t *task, bool cancelled);
159 
160 void task_free_title(retro_task_t *task);
161 
162 bool task_get_cancelled(retro_task_t *task);
163 
164 bool task_get_finished(retro_task_t *task);
165 
166 bool task_get_mute(retro_task_t *task);
167 
168 char* task_get_error(retro_task_t *task);
169 
171 
172 char* task_get_title(retro_task_t *task);
173 
174 void* task_get_data(retro_task_t *task);
175 
176 void task_queue_set_threaded(void);
177 
178 void task_queue_unset_threaded(void);
179 
180 bool task_queue_is_threaded(void);
181 
187 bool task_queue_find(task_finder_data_t *find_data);
188 
196 
197  /* Checks for finished tasks
198  * Takes the finished tasks, if any,
199  * and runs their callbacks.
200  * This must only be called from the main thread. */
201 void task_queue_check(void);
202 
203 /* Pushes a task
204  * The task will start as soon as possible. */
205 void task_queue_push(retro_task_t *task);
206 
207 /* Blocks until all tasks have finished
208  * will return early if cond is not NULL
209  * and cond(data) returns false.
210  * This must only be called from the main thread. */
212 
213 
214 /* Sends a signal to terminate all the tasks.
215  *
216  * This won't terminate the tasks immediately.
217  * They will finish as soon as possible.
218  *
219  * This must only be called from the main thread. */
220 void task_queue_reset(void);
221 
222 /* Deinitializes the task system.
223  * This deinitializes the task system.
224  * The tasks that are running at
225  * the moment will stay on hold */
226 void task_queue_deinit(void);
227 
228 /* Initializes the task system.
229  * This initializes the task system
230  * and chooses an appropriate
231  * implementation according to the settings.
232  *
233  * This must only be called from the main thread. */
234 void task_queue_init(bool threaded, retro_task_queue_msg_t msg_push);
235 
237 
238 #endif
Definition: task_queue.h:37
int link(const char *oldpath, const char *newpath)
Definition: compat_ctype.c:438
void task_queue_cancel_task(void *task)
Definition: task_queue.c:657
void task_queue_retriever_info_free(task_retriever_info_t *list)
Definition: task_queue.c:676
bool task_get_cancelled(retro_task_t *task)
Definition: task_queue.c:759
void * task_get_data(retro_task_t *task)
Definition: task_queue.c:748
#define RETRO_BEGIN_DECLS
Definition: retro_common_api.h:41
void task_set_progress(retro_task_t *task, int8_t progress)
Definition: task_queue.c:711
void * user_data
Definition: task_queue.h:93
Definition: task_queue.h:42
task_type
Definition: task_queue.h:35
Definition: task_queue.h:123
bool task_queue_find(task_finder_data_t *find_data)
Definition: task_queue.c:584
task_retriever_info_t * list
Definition: task_queue.h:134
void task_set_cancelled(retro_task_t *task, bool cancelled)
Definition: task_queue.c:732
void task_queue_reset(void)
Definition: task_queue.c:649
static int cond(LexState *ls)
Definition: lparser.c:1177
bool cancelled
Definition: task_queue.h:84
void * userdata
Definition: task_queue.h:120
void task_queue_push(retro_task_t *task)
Definition: task_queue.c:612
int8_t task_get_progress(retro_task_t *task)
Definition: task_queue.c:803
retro_task_handler_t handler
Definition: task_queue.h:69
void task_set_finished(retro_task_t *task, bool finished)
Definition: task_queue.c:690
void task_free_title(retro_task_t *task)
Definition: task_queue.c:739
retro_task_callback_t callback
Definition: task_queue.h:72
struct task_retriever_data task_retriever_data_t
typedef void(__stdcall *PFN_DESTRUCTION_CALLBACK)(void *pData)
void task_queue_retrieve(task_retriever_data_t *data)
Definition: task_queue.c:591
void task_set_error(retro_task_t *task, char *error)
Definition: task_queue.c:704
Definition: ibxm.h:9
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: glext.h:6303
typedef bool(RETRO_CALLCONV *retro_replace_image_index_t)(unsigned index
bool task_get_mute(retro_task_t *task)
Definition: task_queue.c:781
Definition: task_queue.h:62
char * task_get_title(retro_task_t *task)
Definition: task_queue.c:814
void * task_queue_retriever_info_next(task_retriever_info_t **link)
Definition: task_queue.c:662
void task_queue_check(void)
Definition: task_queue.c:596
void task_queue_deinit(void)
Definition: task_queue.c:544
retro_task_handler_t handler
Definition: task_queue.h:131
void(* progress_cb)(retro_task_t *)
Definition: task_queue.h:105
struct task_retriever_info task_retriever_info_t
void task_queue_unset_threaded(void)
Definition: task_queue.c:574
Definition: task_queue.h:117
void task_queue_set_threaded(void)
Definition: task_queue.c:569
bool finished
Definition: task_queue.h:80
void(* retro_task_callback_t)(void *task_data, void *user_data, const char *error)
Definition: task_queue.h:47
bool(* retro_task_finder_t)(retro_task_t *task, void *userdata)
Definition: task_queue.h:52
static const unsigned char msg[]
Definition: ccm.c:375
static l_noret error(LoadState *S, const char *why)
Definition: lundump.c:39
char * error
Definition: task_queue.h:100
Definition: task_queue.h:129
bool(* retro_task_condition_fn_t)(void *data)
Definition: task_queue.h:60
Definition: task_queue.h:67
void * state
Definition: task_queue.h:96
void * task_data
Definition: task_queue.h:90
#define RETRO_END_DECLS
Definition: retro_common_api.h:42
struct task_finder_data task_finder_data_t
bool(* retro_task_retriever_t)(retro_task_t *task, void *data)
Definition: task_queue.h:58
retro_task_retriever_t func
Definition: task_queue.h:133
void(* retro_task_queue_msg_t)(const char *msg, unsigned prio, unsigned duration, bool flush)
Definition: task_queue.h:55
struct task_retriever_info * next
Definition: task_queue.h:125
void task_set_mute(retro_task_t *task, bool mute)
Definition: task_queue.c:697
retro_task_t * next
Definition: task_queue.h:114
size_t element_size
Definition: task_queue.h:132
int8_t progress
Definition: task_queue.h:103
void task_queue_init(bool threaded, retro_task_queue_msg_t msg_push)
Definition: task_queue.c:551
void * data
Definition: task_queue.h:126
void task_queue_wait(retro_task_condition_fn_t cond, void *data)
Definition: task_queue.c:644
retro_task_finder_t func
Definition: task_queue.h:119
char * source_file
Definition: task_queue.h:64
retro_task_handler_t cleanup
Definition: task_queue.h:76
enum task_type type
Definition: task_queue.h:111
bool mute
Definition: task_queue.h:87
char * task_get_error(retro_task_t *task)
Definition: task_queue.c:792
char * title
Definition: task_queue.h:109
void task_set_title(retro_task_t *task, char *title)
Definition: task_queue.c:718
signed char int8_t
Definition: stdint.h:121
bool task_get_finished(retro_task_t *task)
Definition: task_queue.c:770
bool task_queue_is_threaded(void)
Definition: task_queue.c:579
void task_set_data(retro_task_t *task, void *data)
Definition: task_queue.c:725
void(* retro_task_handler_t)(retro_task_t *task)
Definition: task_queue.h:50