Lines Matching defs:tasks
121 struct loadtasks *tasks = __libc_malloc(sizeof(struct loadtasks));
122 if (tasks) {
123 tasks->array = NULL;
124 tasks->capacity = 0;
125 tasks->length = 0;
126 return tasks;
131 bool append_loadtasks(struct loadtasks *tasks, struct loadtask *item)
133 if (tasks->length + 1 > tasks->capacity) {
135 new_cap = tasks->capacity + TASK_BASE_CAPACITY;
137 if (tasks->array) {
138 realloced = __libc_realloc(tasks->array, new_cap * sizeof(struct loadtask *));
143 tasks->array = realloced;
144 tasks->capacity = new_cap;
149 tasks->array[tasks->length] = item;
150 tasks->length += 1;
188 struct loadtask *get_loadtask(struct loadtasks *tasks, size_t index)
190 if (tasks && tasks->array && (index < tasks->length)) {
191 return tasks->array[index];
197 void free_loadtasks(struct loadtasks *tasks)
199 if (tasks) {
200 if (tasks->length) {
201 for (int i = 0; i < tasks->length; i++) {
202 free_task(get_loadtask(tasks, i));
204 tasks->length = 0;
206 if (tasks->array) {
207 __libc_free(tasks->array);
208 tasks->array = NULL;
210 tasks->capacity = 0;
211 __libc_free(tasks);
215 void shuffle_loadtasks(struct loadtasks *tasks)
219 for (size_t i = 0; i < tasks->length; i++) {
224 index %= tasks->length;
225 task = tasks->array[i];
226 tasks->array[i] = tasks->array[index];
227 tasks->array[index] = task;