[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: does SIMPLEQ_REMOVE_HEAD() work ?
- To: tech_(_at_)_openbsd_(_dot_)_org
- Subject: Re: does SIMPLEQ_REMOVE_HEAD() work ?
- From: "Chris, the Young One" <cky_(_at_)_pobox_(_dot_)_com>
- Date: Thu, 20 Jul 2000 17:00:20 +1200
- Mail-followup-to: tech_(_at_)_openbsd_(_dot_)_org
- Mail-reply-to: young1_(_at_)_hedgee_(_dot_)_com
I left the code untrimmed so I can refer to it. I'm also posting this
message to the list.
On Wed, Jul 19, 2000 at 01:30:30PM -0700, Marco S Hyman wrote:
! > ! ! #define SIMPLEQ_REMOVE_HEAD(head, elm, field) do { \
! > ! ! if (((head)->sqh_first = (elm)->field.sqe_next) == NULL)\
! > ! ! (head)->sqh_last = &(head)->sqh_first; \
! > ! ! } while (0)
!
! It's not a loop. The do { ... } while (0) construct just guarantees that
! the macro is a single statement and can be used anyplace a statement
! can be used.
It happens to be one of my favourite techniques! I wasn't assuming it
was a loop, no matter what. Nothing I said should be taken to mean that
way.
What the code does, is to take set the head of the list to the ``next''
of elm. Hence, the head of the list becomes the element after elm, and
that explains why I said all elements, up to and including elm, are
removed.
! elm would be needed to return the value removed from the queue
! so you can free it.
elm isn't changed, so how can it be used to return anything?
! I don't understand why the macro is written that
! way, but see /sys/net/if_bridge.c for an example of its use.
I have looked. I interpret its use this way (see bridge_flushrule()):
p is first set to the first item. While the queue is not empty, q is
set to the item after p; p is removed (by SIMPLEQ_REMOVE_HEAD), and
freed; p is set to q (i.e., the item after the original p).
SIMPLEQ_REMOVE_HEAD does not return anything in p; p was previously
set (to either SIMPLEQ_FIRST or q). It has to remove an item at a
time, so that, like you said, each item can be freed.
That doesn't invalidate my statement about SIMPLEQ_REMOVE_HEAD taking
out all values of the list from the head up to and including p, in this
case: since p is always the first item of the list (due to ``p = q''),
only one item gets removed at a time.
In that light, I think that the man page needs fixing soon, pending
further outside opinion. I don't mean this post to sound inflammatory
but I clearly still stand by my opinion.
Cheers,
---Chris K.
--
Chris, the Young One |_ but what's a dropped message between friends?
Auckland, New Zealand |_ this is UDP, not TCP after all ;) ---John H.
http://cloud9.hedgee.com/ |_ Robinson, IV
PGP: 0xCCC6114E/0x706A6AAD |_
Visit your host, monkey.org