-/* $OpenBSD: ifq.c,v 1.11 2017/05/03 20:55:29 mikeb Exp $ */
+/* $OpenBSD: ifq.c,v 1.12 2017/06/02 00:07:12 dlg Exp $ */
/*
* Copyright (c) 2015 David Gwynne <dlg@openbsd.org>
void
ifq_serialize(struct ifqueue *ifq, struct task *t)
{
- struct mbuf_list ml = MBUF_LIST_INITIALIZER();
struct task work;
if (ISSET(t->t_flags, TASK_ONQUEUE))
mtx_enter(&ifq->ifq_task_mtx);
}
- /*
- * ifq->ifq_free is only modified by dequeue, which
- * is only called from within this serialization
- * context. it is therefore safe to access and modify
- * here without taking ifq->ifq_mtx.
- */
- ml = ifq->ifq_free;
- ml_init(&ifq->ifq_free);
-
ifq->ifq_serializer = NULL;
}
mtx_leave(&ifq->ifq_task_mtx);
-
- ml_purge(&ml);
}
int
return (dm == m ? ENOBUFS : 0);
}
+static inline void
+ifq_deq_enter(struct ifqueue *ifq)
+{
+ mtx_enter(&ifq->ifq_mtx);
+}
+
+static inline void
+ifq_deq_leave(struct ifqueue *ifq)
+{
+ struct mbuf_list ml;
+
+ ml = ifq->ifq_free;
+ ml_init(&ifq->ifq_free);
+
+ mtx_leave(&ifq->ifq_mtx);
+
+ if (!ml_empty(&ml))
+ ml_purge(&ml);
+}
+
struct mbuf *
ifq_deq_begin(struct ifqueue *ifq)
{
struct mbuf *m = NULL;
void *cookie;
- mtx_enter(&ifq->ifq_mtx);
+ ifq_deq_enter(ifq);
if (ifq->ifq_len == 0 ||
(m = ifq->ifq_ops->ifqop_deq_begin(ifq, &cookie)) == NULL) {
- mtx_leave(&ifq->ifq_mtx);
+ ifq_deq_leave(ifq);
return (NULL);
}
ifq->ifq_ops->ifqop_deq_commit(ifq, m, cookie);
ifq->ifq_len--;
- mtx_leave(&ifq->ifq_mtx);
+ ifq_deq_leave(ifq);
}
void
{
KASSERT(m != NULL);
- mtx_leave(&ifq->ifq_mtx);
+ ifq_deq_leave(ifq);
}
struct mbuf *
void
ifq_mfreem(struct ifqueue *ifq, struct mbuf *m)
{
- IFQ_ASSERT_SERIALIZED(ifq);
+ MUTEX_ASSERT_LOCKED(&ifq->ifq_mtx);
ifq->ifq_len--;
ifq->ifq_qdrops++;
void
ifq_mfreeml(struct ifqueue *ifq, struct mbuf_list *ml)
{
- IFQ_ASSERT_SERIALIZED(ifq);
+ MUTEX_ASSERT_LOCKED(&ifq->ifq_mtx);
ifq->ifq_len -= ml_len(ml);
ifq->ifq_qdrops += ml_len(ml);