+/**
+ * @internal Handle the packet mbufs with attached pinned external buffer
+ * on the mbuf freeing:
+ *
+ * - return zero if reference counter in shinfo is one. It means there is
+ * no more reference to this pinned buffer and mbuf can be returned to
+ * the pool
+ *
+ * - otherwise (if reference counter is not one), decrement reference
+ * counter and return non-zero value to prevent freeing the backing mbuf.
+ *
+ * Returns non zero if mbuf should not be freed.
+ */
+static inline int __rte_pktmbuf_pinned_extbuf_decref(struct rte_mbuf *m)
+{
+ struct rte_mbuf_ext_shared_info *shinfo;
+
+ /* Clear flags, mbuf is being freed. */
+ m->ol_flags = EXT_ATTACHED_MBUF;
+ shinfo = m->shinfo;
+
+ /* Optimize for performance - do not dec/reinit */
+ if (likely(rte_mbuf_ext_refcnt_read(shinfo) == 1))
+ return 0;
+
+ /*
+ * Direct usage of add primitive to avoid
+ * duplication of comparing with one.
+ */
+ if (likely(rte_atomic16_add_return
+ (&shinfo->refcnt_atomic, -1)))
+ return 1;
+
+ /* Reinitialize counter before mbuf freeing. */
+ rte_mbuf_ext_refcnt_set(shinfo, 1);
+ return 0;
+}
+