summaryrefslogtreecommitdiffstats
path: root/sys/sys/mbuf.h
diff options
context:
space:
mode:
authornp <np@FreeBSD.org>2013-08-29 23:46:38 +0000
committernp <np@FreeBSD.org>2013-08-29 23:46:38 +0000
commitb31ce9ec798f31a4e3eb32e171adf40f93209e2b (patch)
tree3bcad51a456eab4d522e6ea16c86eebba7c48d68 /sys/sys/mbuf.h
parentf5ff33730e4d7c8ed7baf90dfb75a20ee45fdfd0 (diff)
downloadFreeBSD-src-b31ce9ec798f31a4e3eb32e171adf40f93209e2b.zip
FreeBSD-src-b31ce9ec798f31a4e3eb32e171adf40f93209e2b.tar.gz
Add a routine for attaching an mbuf to a buffer with an external
refcount. This one is willing to work with buffers that may already be referenced. MEXTADD/m_extadd are suitable only for the first attachment to a cluster -- they initialize the refcount to 1.
Diffstat (limited to 'sys/sys/mbuf.h')
-rw-r--r--sys/sys/mbuf.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/sys/sys/mbuf.h b/sys/sys/mbuf.h
index 930a322..bc2924a 100644
--- a/sys/sys/mbuf.h
+++ b/sys/sys/mbuf.h
@@ -545,6 +545,28 @@ m_gettype(int size)
return (type);
}
+/*
+ * Associated an external reference counted buffer with an mbuf.
+ */
+static __inline void
+m_extaddref(struct mbuf *m, caddr_t buf, u_int size, u_int *ref_cnt,
+ int (*freef)(struct mbuf *, void *, void *), void *arg1, void *arg2)
+{
+
+ KASSERT(ref_cnt != NULL, ("%s: ref_cnt not provided", __func__));
+
+ atomic_add_int(ref_cnt, 1);
+ m->m_flags |= M_EXT;
+ m->m_ext.ext_buf = buf;
+ m->m_ext.ref_cnt = ref_cnt;
+ m->m_data = m->m_ext.ext_buf;
+ m->m_ext.ext_size = size;
+ m->m_ext.ext_free = freef;
+ m->m_ext.ext_arg1 = arg1;
+ m->m_ext.ext_arg2 = arg2;
+ m->m_ext.ext_type = EXT_EXTREF;
+}
+
static __inline uma_zone_t
m_getzone(int size)
{
OpenPOWER on IntegriCloud