aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Dunwoodie <ncon@mail.noconroy.net>2019-09-22 10:38:13 +0200
committerMatt Dunwoodie <ncon@mail.noconroy.net>2019-09-22 11:30:24 +0200
commit5b50eac70754f386fdec9950b20226d9c0b455a5 (patch)
tree4e3f91a7b04946bf88d29e2e7280d833d3a3940a
parentChanging mpq.h again (diff)
downloadwireguard-openbsd-5b50eac70754f386fdec9950b20226d9c0b455a5.tar.xz
wireguard-openbsd-5b50eac70754f386fdec9950b20226d9c0b455a5.zip
Reduce complication of mpq
-rw-r--r--src/mpq.h47
1 files changed, 13 insertions, 34 deletions
diff --git a/src/mpq.h b/src/mpq.h
index ee1aabc..4ebeaa3 100644
--- a/src/mpq.h
+++ b/src/mpq.h
@@ -36,23 +36,20 @@ void mpq_enlist(struct mpq *, struct mbuf_list *);
struct mbuf *mpq_dethread(struct mpq *);
struct mbuf *mpq_dequeue(struct mpq *);
void mpq_done(struct mbuf *m);
-void mpq_dead(struct mbuf *m);
#define MPQ_WORKER(fn_name, parallel_fn, serial_fn) \
-void fn_name(struct mpq *mpq) { \
+void fn_name(void *_mpq) { \
struct mbuf *m; \
+ struct mpq *mpq = _mpq; \
while ((m = mpq_dethread(mpq)) != NULL) { \
- if (parallel_fn(m) == 0) \
- mpq_done(m); \
- else \
- mpq_dead(m); \
- \
- if (mpq_serialize_try_enter(mpq) == 0) { \
- while((m = mpq_dequeue(mpq)) != NULL) { \
- serial_fn(m); \
- } \
- mpq_serialize_leave(mpq); \
+ parallel_fn(m); \
+ SET(m->m_flags, M_LINK0); \
+ } \
+ if (mpq_serialize_try_enter(mpq) == 0) { \
+ while((m = mpq_dequeue(mpq)) != NULL) { \
+ serial_fn(m); \
} \
+ mpq_serialize_leave(mpq); \
} \
} \
@@ -89,7 +86,6 @@ mpq_serialize_leave(struct mpq *mpq)
void
mpq_enqueue(struct mpq *mpq, struct mbuf *m)
{
- CLR(m->m_flags, M_PROTO1);
CLR(m->m_flags, M_LINK0);
mtx_enter(&mpq->mpq_mtx);
ml_enqueue(&mpq->mpq_list, m);
@@ -121,31 +117,14 @@ struct mbuf
struct mbuf
*mpq_dequeue(struct mpq *mpq)
{
- struct mbuf *m = NULL;
- struct mbuf_list freeq = MBUF_LIST_INITIALIZER();
+ struct mbuf *m;
mtx_enter(&mpq->mpq_mtx);
- while (ISSET(MBUF_LIST_FIRST(&mpq->mpq_list)->m_flags, M_LINK0)) {
+ m = MBUF_LIST_FIRST(&mpq->mpq_list);
+ if (m != NULL && ISSET(m->m_flags, M_LINK0))
m = ml_dequeue(&mpq->mpq_list);
- if (ISSET(m->m_flags, M_PROTO1))
- break;
- ml_enqueue(&freeq, m);
+ else
m = NULL;
- }
mtx_leave(&mpq->mpq_mtx);
- ml_purge(&freeq);
return m;
}
-
-void
-mpq_done(struct mbuf *m)
-{
- SET(m->m_flags, M_PROTO1);
- SET(m->m_flags, M_LINK0);
-}
-
-void
-mpq_dead(struct mbuf *m)
-{
- SET(m->m_flags, M_LINK0);
-}
#endif /* _MPQ_H_ */