qemu-devel
[Top][All Lists]
Advanced

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

Re: all class init functions for all types in QEMU are called in select_


From: Paolo Bonzini
Subject: Re: all class init functions for all types in QEMU are called in select_machine(). Expected?
Date: Fri, 12 Mar 2021 18:04:15 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.0

On 12/03/21 14:40, Claudio Fontana wrote:
     /*
      * double dispatch. The first callback allows the accel cpu
      * to run initializations for the CPU,
      * the second one allows the CPU to customize the accel cpu
      * behavior according to the CPU.
      *
      * The second is currently only used by TCG, to specialize the
      * TCGCPUOps depending on the CPU type.
      */
     cc->accel_cpu = accel_cpu;
     if (accel_cpu->cpu_class_init) {
         accel_cpu->cpu_class_init(cc);
     }
     if (cc->init_accel_cpu) {
         cc->init_accel_cpu(accel_cpu, cc);
     }
}

.. but maybe this is premature, and should wait for actual users of this beyond 
TCG on ARM?

I prefer to single out TCG and have the call in cpu_class_init. The idea of double dispatch (as opposed to an if/else chain with checks on the class of the argument) is that the first caller uses different "method names" to tell its type name to the target.

See for example https://en.wikipedia.org/wiki/Double_dispatch#Example_in_Ruby.

Paolo




reply via email to

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