svn commit: r278914 - in head/sys: kern sys
Gleb Smirnoff
glebius at FreeBSD.org
Tue Feb 17 19:32:12 UTC 2015
Author: glebius
Date: Tue Feb 17 19:32:11 2015
New Revision: 278914
URL: https://svnweb.freebsd.org/changeset/base/278914
Log:
Use anonymous unions to add possibility to put mbufs into queue(3)
STAILQs and SLISTs using the same structure field as good old m_next
and m_nextpkt linkage occupy.
New code is encouraged to use queue(3) macros, instead of implementing
the wheel. However, better not to have a mixture of old style and
queue(3) in one file or subsystem.
Reviewed by: rwatson, rrs, rpaulo
Differential Revision: D1499
Modified:
head/sys/kern/uipc_mbuf.c
head/sys/sys/mbuf.h
Modified: head/sys/kern/uipc_mbuf.c
==============================================================================
--- head/sys/kern/uipc_mbuf.c Tue Feb 17 19:27:14 2015 (r278913)
+++ head/sys/kern/uipc_mbuf.c Tue Feb 17 19:32:11 2015 (r278914)
@@ -120,6 +120,18 @@ CTASSERT(sizeof(struct struct_m_ext) ==
#endif
/*
+ * Assert that the queue(3) macros produce code of the same size as an old
+ * plain pointer does.
+ */
+#ifdef INVARIANTS
+static struct mbuf m_assertbuf;
+CTASSERT(sizeof(m_assertbuf.m_slist) == sizeof(m_assertbuf.m_next));
+CTASSERT(sizeof(m_assertbuf.m_stailq) == sizeof(m_assertbuf.m_next));
+CTASSERT(sizeof(m_assertbuf.m_slistpkt) == sizeof(m_assertbuf.m_nextpkt));
+CTASSERT(sizeof(m_assertbuf.m_stailqpkt) == sizeof(m_assertbuf.m_nextpkt));
+#endif
+
+/*
* m_get2() allocates minimum mbuf that would fit "size" argument.
*/
struct mbuf *
Modified: head/sys/sys/mbuf.h
==============================================================================
--- head/sys/sys/mbuf.h Tue Feb 17 19:27:14 2015 (r278913)
+++ head/sys/sys/mbuf.h Tue Feb 17 19:32:11 2015 (r278914)
@@ -184,8 +184,16 @@ struct mbuf {
* Compile-time assertions in uipc_mbuf.c test these values to ensure
* that they are correct.
*/
- struct mbuf *m_next; /* next buffer in chain */
- struct mbuf *m_nextpkt; /* next chain in queue/record */
+ union { /* next buffer in chain */
+ struct mbuf *m_next;
+ SLIST_ENTRY(mbuf) m_slist;
+ STAILQ_ENTRY(mbuf) m_stailq;
+ };
+ union { /* next chain in queue/record */
+ struct mbuf *m_nextpkt;
+ SLIST_ENTRY(mbuf) m_slistpkt;
+ STAILQ_ENTRY(mbuf) m_stailqpkt;
+ };
caddr_t m_data; /* location of data */
int32_t m_len; /* amount of data in this mbuf */
uint32_t m_type:8, /* type of data in this mbuf */
More information about the svn-src-head
mailing list