qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH RFC v3 03/21] qom: Introduce CPU class


From: Anthony Liguori
Subject: Re: [Qemu-devel] [PATCH RFC v3 03/21] qom: Introduce CPU class
Date: Mon, 06 Feb 2012 15:22:16 -0600
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.23) Gecko/20110922 Lightning/1.0b2 Thunderbird/3.1.15

On 02/06/2012 02:14 PM, Andreas Färber wrote:
Am 06.02.2012 20:24, schrieb Anthony Liguori:
On 02/02/2012 08:59 PM, Andreas Färber wrote:
+/**
+ * cpu_common_reset:
+ * @cpu: The CPU whose common state is to be reset.
+ *
+ * To be used by derived classes.
+ */
+void cpu_common_reset(CPU *cpu);

Make this static, initialize reset = cpu_common_reset in
cpu_class_initfn, then in the derived class initfn, save the pointer to
the parent reset function so it can be called later.

I don't see how that would work. To initialize, e.g., the ARMCPUClass
with additional class fields I'm overriding the .class_init.

You're not overriding the class_init. The class init for a type is called when that class is initialized for the first time. See the documentation in object.h.

When class_init is called, the parent class type's class_init has already been called and the default values are set. So:

static void arm_cpu_reset(CPUCommon *cpu)
{
   ARMCPU *s = ARM_CPU(cpu);
   ARMCPUClass *ac = ARM_CPU_GET_CLASS(s);

   // do arm specific reset

   // call super class reset
   ac->super_reset(cpu);
}

static void arm_cpu_class_initfn(ObjectClass *klass, void *data)
{
   CPUCommonClass *cc = CPU_COMMON_CLASS(klass);
   ARMCPUClass *ac = ARM_CPU_CLASS(klass);

   // cc->reset was set in CPUCommonClass's class_init
   ac->super_reset = cc->reset;
   cc->reset = arm_cpu_reset;
}

It's admittedly a little funky but this is the common idiom in gobject. I'm not sure there's a better way.

Regards,

Anthony Liguori

 So in order
to let CPUClass initialize the reset callback to its static one I'd need
to make CPU's class_init function non-static so that I can call that
from my derived class' class_init function, no?

Andreas





reply via email to

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