Debian Codegraph @

libretro-common/include/queues/task_queue.h

raw symbols SCIP
1 /* Copyright (C) 2010-2016 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 <boolean.h>
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 enum task_queue_ctl_state
34 {
35 TASK_QUEUE_CTL_NONE = 0,
36
37 /* Deinitializes the task system.
38 * This deinitializes the task system.
39 * The tasks that are running at
40 * the moment will stay on hold
41 * until TASK_QUEUE_CTL_INIT is called again. */
42 TASK_QUEUE_CTL_DEINIT,
43
44 /* Initializes the task system.
45 * This initializes the task system
46 * and chooses an appropriate
47 * implementation according to the settings.
48 *
49 * This must only be called from the main thread. */
50 TASK_QUEUE_CTL_INIT,
51
52 /**
53 * Calls func for every running task
54 * until it returns true.
55 * Returns a task or NULL if not found.
56 */
57 TASK_QUEUE_CTL_FIND,
58
59 /* Blocks until all tasks have finished.
60 * This must only be called from the main thread. */
61 TASK_QUEUE_CTL_WAIT,
62
63 /* Checks for finished tasks
64 * Takes the finished tasks, if any,
65 * and runs their callbacks.
66 * This must only be called from the main thread. */
67 TASK_QUEUE_CTL_CHECK,
68
69 /* Pushes a task
70 * The task will start as soon as possible. */
71 TASK_QUEUE_CTL_PUSH,
72
73 /* Sends a signal to terminate all the tasks.
74 *
75 * This won't terminate the tasks immediately.
76 * They will finish as soon as possible.
77 *
78 * This must only be called from the main thread. */
79 TASK_QUEUE_CTL_RESET,
80
81 TASK_QUEUE_CTL_SET_THREADED,
82
83 TASK_QUEUE_CTL_UNSET_THREADED,
84
85 TASK_QUEUE_CTL_IS_THREADED
86 };
87
88 typedef struct retro_task retro_task_t;
89 typedef void (*retro_task_callback_t)(void *task_data,
90 void *user_data, const char *error);
91
92 typedef void (*retro_task_handler_t)(retro_task_t *task);
93
94 typedef bool (*retro_task_finder_t)(retro_task_t *task,
95 void *userdata);
96
97 typedef struct
98 {
99 char *source_file;
100 } decompress_task_data_t;
101
102 struct retro_task
103 {
104 retro_task_handler_t handler;
105
106 /* always called from the main loop */
107 retro_task_callback_t callback;
108
109 /* set to true by the handler to signal
110 * the task has finished executing. */
111 bool finished;
112
113 /* set to true by the task system
114 * to signal the task *must* end. */
115 bool cancelled;
116
117 /* created by the handler, destroyed by the user */
118 void *task_data;
119
120 /* owned by the user */
121 void *user_data;
122
123 /* created and destroyed by the code related to the handler */
124 void *state;
125
126 /* created by task handler; destroyed by main loop
127 * (after calling the callback) */
128 char *error;
129
130 /* -1 = unmettered, 0-100 progress value */
131 int8_t progress;
132
133 /* handler can modify but will be
134 * free()d automatically if non-NULL. */
135 char *title;
136
137 /* don't touch this. */
138 retro_task_t *next;
139 };
140
141 typedef struct task_finder_data
142 {
143 retro_task_finder_t func;
144 void *userdata;
145 } task_finder_data_t;
146
147 void task_queue_push_progress(retro_task_t *task);
148
149 bool task_queue_ctl(enum task_queue_ctl_state state, void *data);
150
151 #ifdef __cplusplus
152 }
153 #endif
154
155 #endif