1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-18 10:35:55 +00:00

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
This commit is contained in:
Gleb Smirnoff 2015-02-17 19:32:11 +00:00
parent cc4a90c445
commit ec9d83dd9b
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=278914
2 changed files with 22 additions and 2 deletions

View File

@ -119,6 +119,18 @@ CTASSERT(sizeof(struct pkthdr) == 48);
CTASSERT(sizeof(struct struct_m_ext) == 28);
#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.
*/

View File

@ -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 */