Subject: Re: SoC ideas - mbuf API
To: None <tech-net@NetBSD.org>
From: Pavel Cahyna <pavel@netbsd.org>
List: tech-net
Date: 06/28/2006 01:19:33
On Tue, Jun 27, 2006 at 04:07:23PM -0700, Jason Thorpe wrote:
>
> On Jun 27, 2006, at 2:29 PM, Pavel Cahyna wrote:
>
> If we're going to rework / add mbuf APIs, I'd like to propose
> something a little more radical...
>
> - Make mbufs an opaque type... "typedef struct mbuf *mbuf_t;", hide
> the definition of "struct mbuf", and use accessors / mutators that
> have well-defined semantics to make it less easy for mbuf users to
> screw themselves.
>
> - mbuf_data() would return a const void *. If a user wants a
> writable buffer, then mbuf_mutable_data() would return a void *.
> This would allow us to encapsulate the whole "make writable" thing,
> and allow us also to keep some state in the mbuf itself to possibly
> avoid unnecessary iterations over the chain (if it's already
> mutable). Anyway, this would also force us to const poison the
> networking code, which in turn would help the compiler generate
> better code which in turn could lead to better performance. It's all
> good.
Isn't it mostly what I have proposed? I have proposed mptr_rw returning
writable pointer, and mptr... returning const pointer.
A difference is that the proposed macros would also do the cast to the
required data type, to be more similar to the current mtod() and at the
same time to be able to use sizeof on this type.
Pavel