aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorMarvin Borner2023-06-01 17:33:56 +0200
committerMarvin Borner2023-06-01 17:33:56 +0200
commitc062eaeea09592cbdf7e5d732e992d0cdd8eedc5 (patch)
tree23cdfd41e6a492338c9f902b3a2206a642746530 /src/lib
parentccd4914d395b5a588868cffaad580c29167e6747 (diff)
More scheduling
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/pqueue.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/lib/pqueue.c b/src/lib/pqueue.c
index c080bb2..cf0611f 100644
--- a/src/lib/pqueue.c
+++ b/src/lib/pqueue.c
@@ -35,7 +35,8 @@
#define parent(i) ((i) >> 1)
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)
{
struct pqueue *q;
@@ -51,7 +52,9 @@ struct pqueue *pqueue_init(size_t n, pqueue_cmp_pri_f cmppri,
q->size = 1;
q->avail = q->step = (n + 1); /* see comment above about n+1 */
q->cmppri = cmppri;
+ q->setpri = setpri;
q->getpri = getpri;
+ q->getpos = getpos;
q->setpos = setpos;
return q;
@@ -144,6 +147,19 @@ int pqueue_insert(struct pqueue *q, void *d)
return 0;
}
+void pqueue_change_priority(struct pqueue *q, pqueue_pri_t new_pri, void *d)
+{
+ size_t posn;
+ pqueue_pri_t old_pri = q->getpri(d);
+
+ q->setpri(d, new_pri);
+ posn = q->getpos(d);
+ if (q->cmppri(old_pri, new_pri))
+ bubble_up(q, posn);
+ else
+ percolate_down(q, posn);
+}
+
void *pqueue_pop(struct pqueue *q)
{
void *head;