From c062eaeea09592cbdf7e5d732e992d0cdd8eedc5 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Thu, 1 Jun 2023 17:33:56 +0200 Subject: More scheduling --- inc/lib/pqueue.h | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'inc/lib') diff --git a/inc/lib/pqueue.h b/inc/lib/pqueue.h index 86c4080..732002e 100644 --- a/inc/lib/pqueue.h +++ b/inc/lib/pqueue.h @@ -42,6 +42,7 @@ typedef unsigned long long pqueue_pri_t; /** callback functions to get/set/compare the priority of an element */ typedef pqueue_pri_t (*pqueue_get_pri_f)(void *a); +typedef void (*pqueue_set_pri_f)(void *a, pqueue_pri_t pri); typedef int (*pqueue_cmp_pri_f)(pqueue_pri_t next, pqueue_pri_t curr); /** callback functions to get/set the position of an element */ @@ -58,6 +59,8 @@ struct pqueue { size_t step; /**< growth stepping setting */ pqueue_cmp_pri_f cmppri; /**< callback to compare nodes */ pqueue_get_pri_f getpri; /**< callback to get priority of a node */ + pqueue_set_pri_f setpri; /**< callback to set priority of a node */ + pqueue_get_pos_f getpos; /**< callback to get position of a node */ pqueue_set_pos_f setpos; /**< callback to set position of a node */ void **d; /**< The actualy queue in binary heap form */ }; @@ -70,12 +73,16 @@ struct pqueue { * @param cmppri The callback function to run to compare two elements * This callback should return 0 for 'lower' and non-zero * for 'higher', or vice versa if reverse priority is desired + * @param setpri the callback function to run to assign a score to an element * @param getpri the callback function to run to set a score to an element + * @param getpos the callback function to get the current element's position + * @param setpos the callback function to set the current element's position * * @return the handle or NULL for insufficent memory */ struct pqueue *pqueue_init(size_t n, pqueue_cmp_pri_f cmppri, - pqueue_get_pri_f getpri, pqueue_set_pos_f setpos); + pqueue_get_pri_f getpri, pqueue_set_pri_f setpri, + pqueue_get_pos_f getpos, pqueue_set_pos_f setpos); /** * free all memory used by the queue @@ -97,6 +104,14 @@ size_t pqueue_size(struct pqueue *q); */ int pqueue_insert(struct pqueue *q, void *d); +/** + * move an existing entry to a different priority + * @param q the queue + * @param new_pri the new priority + * @param d the entry + */ +void pqueue_change_priority(struct pqueue *q, pqueue_pri_t new_pri, void *d); + /** * pop the highest-ranking item from the queue. * @param q the queue -- cgit v1.2.3