Traversing a list of LIST_ENTRY structures

All:
Whats the best method of traversing a list of structures that include a
LIST_ENTRY member?

I’m looking for something like:

for(i = 0;i < number of members;i++)
{
do some operation of each member
}

I’m guessing it’ll somehow include the usage of CONTAINING_RECORD but
haven’t yet been able to figure it out.

Thanks,

Chuck

If I need to traverse a LIST_ENTRY, I usually do it this way:

PLIST_ENTRY pListEntry = NULL;
PFOO pFoo = NULL;

pListEntry = listHead.Flink;

while(pListEntry && (pListEntry != &listHead)){
pFoo = (PFOO) CONTAINING_RECORD(pListEntry, FOO, m_listEntry);
//
//Do stuff to pFoo’s members
//
pListEntry = pListEntry->Flink;
}

Of course this is only if you don’t want to pop all the entries.

-Jeff

-----Original Message-----
From: chuck m [mailto:chuck.monarch@hp.com]
Sent: Tuesday, April 01, 2003 1:24 PM
To: NT Developers Interest List
Subject: [ntdev] Traversing a list of LIST_ENTRY structures

All:
Whats the best method of traversing a list of structures that include a
LIST_ENTRY member?

I’m looking for something like:

for(i = 0;i < number of members;i++)
{
do some operation of each member
}

I’m guessing it’ll somehow include the usage of CONTAINING_RECORD but
haven’t yet been able to figure it out.

Thanks,

Chuck


You are currently subscribed to ntdev as: xxxxx@concord.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.
This footnote also confirms that this email message has been swept by
the latest virus scan software available for the presence of computer
viruses.
**********************************************************************

off the top of my head i believe it’s:

PLIST_ENTRY entry

for(entry = list->Flink; entry != list; entry = entry->Flink) {
PFOO foo;

foo = CONTAINING_RECORD(entry, FOO, FooListEntry);
}

-p

-----Original Message-----
From: chuck m [mailto:chuck.monarch@hp.com]
Sent: Tuesday, April 01, 2003 10:24 AM
To: NT Developers Interest List

All:
Whats the best method of traversing a list of structures
that include a LIST_ENTRY member?

I’m looking for something like:

for(i = 0;i < number of members;i++)
{
do some operation of each member
}

I’m guessing it’ll somehow include the usage of
CONTAINING_RECORD but haven’t yet been able to figure it out.

Thanks,

Chuck


You are currently subscribed to ntdev as:
xxxxx@microsoft.com To unsubscribe send a blank email to
xxxxx@lists.osr.com

Yes and pray this does not need to be synchronized across multiple IRQLs.

Oh someone says … “all he needs to do is us the ExInterlockedXxxx
functions.”

Oh says I “suppose he needs to remove a LIST_ENTRY from the middle of the
queue.”

Oh someone says “then he uses RemoveEntry.”

Oh says I “that is unsynchronized and can lead to a corrupted list.”

Oh says Microsoft “We see no need for anyone to ever remove an item in the
middle of a list.”

Oh says I “I have a list of 13 IRPs and the Widget application wants to
cancel #6.”

Oh … forget it …


Gary G. Little
Have Computer, Will Travel …
909-698-3191
909-551-2105
http://www.wd-3.com

“Peter Wieland” wrote in message
news:xxxxx@ntdev…

off the top of my head i believe it’s:

PLIST_ENTRY entry

for(entry = list->Flink; entry != list; entry = entry->Flink) {
PFOO foo;

foo = CONTAINING_RECORD(entry, FOO, FooListEntry);
}

-p

>
> -----Original Message-----
> From: chuck m [mailto:chuck.monarch@hp.com]
> Sent: Tuesday, April 01, 2003 10:24 AM
> To: NT Developers Interest List
>
> All:
> Whats the best method of traversing a list of structures
> that include a LIST_ENTRY member?
>
> I’m looking for something like:
>
> for(i = 0;i < number of members;i++)
> {
> do some operation of each member
> }
>
> I’m guessing it’ll somehow include the usage of
> CONTAINING_RECORD but haven’t yet been able to figure it out.
>
> Thanks,
>
> Chuck
>
>
> —
> You are currently subscribed to ntdev as:
> xxxxx@microsoft.com To unsubscribe send a blank email to
> xxxxx@lists.osr.com
>
>

in other words: make sure you’re not using the interlocked versions of
the list manipulation functions if you need to walk your list or remove
items from the middle of it.

-p

-----Original Message-----
From: Gary G. Little [mailto:xxxxx@aerosurf.net]
Sent: Tuesday, April 01, 2003 3:09 PM
To: NT Developers Interest List

Yes and pray this does not need to be synchronized across
multiple IRQLs.

Oh someone says … “all he needs to do is us the
ExInterlockedXxxx functions.”

Oh says I “suppose he needs to remove a LIST_ENTRY from the
middle of the queue.”

Oh someone says “then he uses RemoveEntry.”

Oh says I “that is unsynchronized and can lead to a corrupted list.”

Oh says Microsoft “We see no need for anyone to ever remove
an item in the middle of a list.”

Oh says I “I have a list of 13 IRPs and the Widget
application wants to cancel #6.”

Oh … forget it …


Gary G. Little
Have Computer, Will Travel …
909-698-3191
909-551-2105
http://www.wd-3.com

“Peter Wieland” wrote in
> message news:xxxxx@ntdev…
>
> off the top of my head i believe it’s:
>
>
> PLIST_ENTRY entry
>
> for(entry = list->Flink; entry != list; entry = entry->Flink)
> { PFOO foo;
>
> foo = CONTAINING_RECORD(entry, FOO, FooListEntry); }
>
> -p
>
> >
> > -----Original Message-----
> > From: chuck m [mailto:chuck.monarch@hp.com]
> > Sent: Tuesday, April 01, 2003 10:24 AM
> > To: NT Developers Interest List
> >
> > All:
> > Whats the best method of traversing a list of structures that
> > include a LIST_ENTRY member?
> >
> > I’m looking for something like:
> >
> > for(i = 0;i < number of members;i++)
> > {
> > do some operation of each member
> > }
> >
> > I’m guessing it’ll somehow include the usage of CONTAINING_RECORD
> > but haven’t yet been able to figure it out.
> >
> > Thanks,
> >
> > Chuck
> >
> >
> > —
> > You are currently subscribed to ntdev as:
> > xxxxx@microsoft.com To unsubscribe send a blank email to
> > xxxxx@lists.osr.com
> >
> >
>
>
>
>
>
> —
> You are currently subscribed to ntdev as:
> xxxxx@microsoft.com To unsubscribe send a blank email to
> xxxxx@lists.osr.com
>
>