Source-Changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: CVS commit: src/sys



On Wed, Feb 06, 2008 at 10:14:18PM +0100, Matthias Drochner wrote:
> 
> dyoung%pobox.com@localhost said:
> > Please put device_foreach_child() back, though, I am using that.
> 
> Just for curiosity, what are you doing?
> 
> I'm thinking about how to get the device list traversals
> protected -- eg the child list in drvctl can be called
> by everyone, and a device removal could interfere with it,
> leading to a crash.
> My ideas spin around an iterator which must be allocated
> and freed, and some counter which tracks the number of
> active iterators. Device removals would be deferred until
> all iterators are freed. That would be more flexible than
> a callback, and easier to use. What do you think?

That sounds fine.  I think that you mean something like this?

        device_iterator iter;
        device_t dv;

        /* deviter_first() acquires a lock against device removal */
        for (dv = deviter_first(&iter); dv != NULL; dv = deviter_next(&iter))
                /* do something */

        /* deviter_release() releases the lock */
        deviter_release(&iter);

I used such an iterator pattern in my recent shutdown patches, but I
didn't lock, I removed devices, and I walked the list forward, oops! :-)

I can think of two cases where I would like to walk the device list
in order to remove devices: at shutdown, and when detaching a device's
children.  Perhaps a reader/writer lock is appropriate?  Perhaps walk
the list backwards in the "writer" case?  Just thinking out loud.

Dave

-- 
David Young             OJC Technologies
dyoung%ojctech.com@localhost      Urbana, IL * (217) 278-3933 ext 24



Home | Main Index | Thread Index | Old Index