-/* $OpenBSD: uipc_mbuf.c,v 1.284 2022/08/14 01:58:28 jsg Exp $ */
+/* $OpenBSD: uipc_mbuf.c,v 1.285 2023/05/05 01:19:51 bluhm Exp $ */
/* $NetBSD: uipc_mbuf.c,v 1.15.4.1 1996/06/13 17:11:44 cgd Exp $ */
/*
return (hdatalen);
}
+void
+mq_set_maxlen(struct mbuf_queue *mq, u_int maxlen)
+{
+ mtx_enter(&mq->mq_mtx);
+ mq->mq_maxlen = maxlen;
+ mtx_leave(&mq->mq_mtx);
+}
+
int
sysctl_mq(int *name, u_int namelen, void *oldp, size_t *oldlenp,
void *newp, size_t newlen, struct mbuf_queue *mq)
case IFQCTL_MAXLEN:
maxlen = mq->mq_maxlen;
error = sysctl_int(oldp, oldlenp, newp, newlen, &maxlen);
- if (!error && maxlen != mq->mq_maxlen) {
- mtx_enter(&mq->mq_mtx);
- mq->mq_maxlen = maxlen;
- mtx_leave(&mq->mq_mtx);
- }
+ if (!error && maxlen != mq->mq_maxlen)
+ mq_set_maxlen(mq, maxlen);
return (error);
case IFQCTL_DROPS:
return (sysctl_rdint(oldp, oldlenp, newp, mq_drops(mq)));
-/* $OpenBSD: mbuf.h,v 1.255 2022/08/15 16:15:37 bluhm Exp $ */
+/* $OpenBSD: mbuf.h,v 1.256 2023/05/05 01:19:51 bluhm Exp $ */
/* $NetBSD: mbuf.h,v 1.19 1996/02/09 18:25:14 christos Exp $ */
/*
* mbuf queues
*/
+#include <sys/atomic.h>
+
#define MBUF_QUEUE_INITIALIZER(_maxlen, _ipl) \
{ MUTEX_INITIALIZER(_ipl), MBUF_LIST_INITIALIZER(), (_maxlen), 0 }
struct mbuf * mq_dechain(struct mbuf_queue *);
unsigned int mq_purge(struct mbuf_queue *);
unsigned int mq_hdatalen(struct mbuf_queue *);
+void mq_set_maxlen(struct mbuf_queue *, u_int);
-#define mq_len(_mq) ml_len(&(_mq)->mq_list)
-#define mq_empty(_mq) ml_empty(&(_mq)->mq_list)
-#define mq_full(_mq) (mq_len((_mq)) >= (_mq)->mq_maxlen)
-#define mq_drops(_mq) ((_mq)->mq_drops)
-#define mq_set_maxlen(_mq, _l) ((_mq)->mq_maxlen = (_l))
+#define mq_len(_mq) READ_ONCE((_mq)->mq_list.ml_len)
+#define mq_empty(_mq) (mq_len(_mq) == 0)
+#define mq_full(_mq) (mq_len((_mq)) >= READ_ONCE((_mq)->mq_maxlen))
+#define mq_drops(_mq) READ_ONCE((_mq)->mq_drops)
#endif /* _KERNEL */
#endif /* _SYS_MBUF_H_ */