]> git.ozlabs.org Git - ccan/blob - ccan/lpq/lpq.c
coroutine: Enable valgrind
[ccan] / ccan / lpq / lpq.c
1 /* GNU LGPL version 2 (or later) - see LICENSE file for details */
2 #include <assert.h>
3
4 #include <ccan/cast/cast.h>
5
6 #include <ccan/lpq/lpq.h>
7
8 static int lpq_cmp(const struct lpq_ *pq, size_t offset,
9                    const struct lpq_link *al, const struct lpq_link *bl)
10 {
11         void *a = (char *)al - offset;
12         void *b = (char *)bl - offset;
13
14         return total_order_cmp(pq->order, a, b);
15 }
16
17 struct lpq_link **lpq_frontp_(struct lpq_ *pq, size_t offset)
18 {
19         struct lpq_link **frontp = &pq->list;
20         struct lpq_link **p;
21
22         if (lpq_empty_(pq))
23                 return NULL;
24
25         for (p = &(pq->list->next); *p; p = &(*p)->next) {
26                 if (lpq_cmp(pq, offset, *p, *frontp) >= 0)
27                         frontp = p;
28         }
29
30         return frontp;
31 }