GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
gp_task.h
1// SPDX-License-Identifier: LGPL-2.1-or-later
2/*
3 * Copyright (C) 2009-2021 Cyril Hrubis <metan@ucw.cz>
4 */
5
6/*
7
8 Tasks are sorted into queues accordingly to its priorities. Queue with
9 smallest priority runs until it's out of tasks. Tasks inside a single queue
10 are schedulled by a round robin.
11
12 */
13
14#ifndef INPUT_GP_TASK_H
15#define INPUT_GP_TASK_H
16
17#include <input/gp_types.h>
18#include <utils/gp_list.h>
19
20#define GP_TASK_NONE_PRIO 0
21/* These are just bounds for the priorities. */
22#define GP_TASK_MIN_PRIO 1
23#define GP_TASK_MAX_PRIO 3
24
25struct gp_task_queue {
26 unsigned int task_cnt;
27 unsigned int min_prio;
28 gp_dlist queues[GP_TASK_MAX_PRIO - GP_TASK_MIN_PRIO + 1];
29};
30
31struct gp_task {
32 gp_dlist_head head;
33 unsigned int prio:3;
34 unsigned int queued:1;
35 char *id;
36 int (*callback)(gp_task *self);
37 void *priv;
38};
39
40void gp_task_queue_dump(gp_task_queue *self);
41
42void gp_task_queue_ins(gp_task_queue *self, gp_task *task);
43
44void gp_task_queue_rem(gp_task_queue *self, gp_task *task);
45
46int gp_task_queue_process(gp_task_queue *self);
47
48static inline size_t gp_task_queue_tasks(gp_task_queue *self)
49{
50 return self->task_cnt;
51}
52
53static inline unsigned int gp_task_queue_head_prio(gp_task_queue *self)
54{
55 return self->min_prio;
56}
57
58#endif /* INPUT_GP_TASK_H */
A linked list implementation.