qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH v2 2/7] ioapic: convert to qdev


From: Paul Brook
Subject: Re: [Qemu-devel] [PATCH v2 2/7] ioapic: convert to qdev
Date: Tue, 15 Jun 2010 01:25:22 +0100
User-agent: KMail/1.13.3 (Linux/2.6.33-2-amd64; KDE/4.4.4; x86_64; ; )

> >> -static void ioapic_reset(void *opaque)
> >> +static void ioapic_reset(DeviceState *d)
> >>  {
> >> -    IOAPICState *s = opaque;
> >> +    IOAPICState *s = container_of(d, IOAPICState, busdev.qdev);
> > 
> > DO_UPCAST()?  I hate it, but it's what the other devices do...
> 
> Both are used:
> grep container_of hw/*.[ch]|wc -l
> 81
> grep DO_UPCAST hw/*.[ch]|wc -l
> 246

Which is appropriate depends on the context.

DO_UPCAST is appropriate when we're dealing with polymorphic types. In this 
case IOAPICState is derived from DeviceState (via SysBusDevice). There is an 
implicit assumption that these are all the same object, so DO_UPCAST is 
approprate.

container_of is approriate when we're embedding one object in annother, but 
without any inheritance relationship between the two.

Paul



reply via email to

[Prev in Thread] Current Thread [Next in Thread]