summaryrefslogtreecommitdiff
path: root/sys/kern
diff options
context:
space:
mode:
authorDavid Gwynne <dlg@cvs.openbsd.org>2020-06-21 05:37:27 +0000
committerDavid Gwynne <dlg@cvs.openbsd.org>2020-06-21 05:37:27 +0000
commit245dcfabb00f21b6ab6dadd445143b5dbdbc3a94 (patch)
treeeed272324f25a0899566c6adf4ef62e705a5b86d /sys/kern
parentc7b329e05dd96c9a121afc63bcf6e4d3efb2f366 (diff)
add mq_push. it's like mq_enqueue, but drops from the head, not the tail.
from Matt Dunwoodie and Jason A. Donenfeld
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/uipc_mbuf.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/sys/kern/uipc_mbuf.c b/sys/kern/uipc_mbuf.c
index 1f2de1f6b24..13342359099 100644
--- a/sys/kern/uipc_mbuf.c
+++ b/sys/kern/uipc_mbuf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uipc_mbuf.c,v 1.274 2020/01/22 22:56:35 dlg Exp $ */
+/* $OpenBSD: uipc_mbuf.c,v 1.275 2020/06/21 05:37:26 dlg Exp $ */
/* $NetBSD: uipc_mbuf.c,v 1.15.4.1 1996/06/13 17:11:44 cgd Exp $ */
/*
@@ -1660,6 +1660,25 @@ mq_init(struct mbuf_queue *mq, u_int maxlen, int ipl)
}
int
+mq_push(struct mbuf_queue *mq, struct mbuf *m)
+{
+ struct mbuf *dropped = NULL;
+
+ mtx_enter(&mq->mq_mtx);
+ if (mq_len(mq) >= mq->mq_maxlen) {
+ mq->mq_drops++;
+ dropped = ml_dequeue(&mq->mq_list);
+ }
+ ml_enqueue(&mq->mq_list, m);
+ mtx_leave(&mq->mq_mtx);
+
+ if (dropped)
+ m_freem(dropped);
+
+ return (dropped != NULL);
+}
+
+int
mq_enqueue(struct mbuf_queue *mq, struct mbuf *m)
{
int dropped = 0;