summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sys/kern/subr_taskqueue.c2
-rw-r--r--sys/sys/queue.h7
2 files changed, 7 insertions, 2 deletions
diff --git a/sys/kern/subr_taskqueue.c b/sys/kern/subr_taskqueue.c
index ab47b4ff2ff7..6d18cb9c95ea 100644
--- a/sys/kern/subr_taskqueue.c
+++ b/sys/kern/subr_taskqueue.c
@@ -136,7 +136,7 @@ taskqueue_enqueue(struct taskqueue *queue, struct task *task)
/*
* Optimise the case when all tasks have the same priority.
*/
- prev = STAILQ_LAST(&queue->tq_queue);
+ prev = STAILQ_LAST(&queue->tq_queue, task, ta_link);
if (!prev || prev->ta_priority >= task->ta_priority) {
STAILQ_INSERT_TAIL(&queue->tq_queue, task, ta_link);
} else {
diff --git a/sys/sys/queue.h b/sys/sys/queue.h
index 5565b8201380..0b30e915bf67 100644
--- a/sys/sys/queue.h
+++ b/sys/sys/queue.h
@@ -196,7 +196,12 @@ struct { \
} while (0)
#define STAILQ_FIRST(head) ((head)->stqh_first)
-#define STAILQ_LAST(head) (*(head)->stqh_last)
+
+#define STAILQ_LAST(head, type, field) \
+ (STAILQ_EMPTY(head) ? \
+ NULL : \
+ ((struct type *) \
+ ((char *)((head)->stqh_last) - __offsetof(struct type, field))))
#define STAILQ_FOREACH(var, head, field) \
for((var) = (head)->stqh_first; (var); (var) = (var)->field.stqe_next)