qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH 2/7] iohandlers: Introduce a new API


From: Anthony Liguori
Subject: Re: [Qemu-devel] [PATCH 2/7] iohandlers: Introduce a new API
Date: Tue, 22 Feb 2011 12:21:24 -0600
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.15) Gecko/20101027 Lightning/1.0b1 Thunderbird/3.0.10

On 02/22/2011 10:21 AM, Avi Kivity wrote:
On 02/22/2011 05:00 PM, Anthony Liguori wrote:

Drop the opaque, instead put the IOHandler in there (or maybe the CharDev?) and use container_of().


You know, I'm not there that this is automatically better.

Why not?  One less unsafe cast.

It turns out there are a lot of cases in QEMU where there isn't an obvious data structure to piggy back on.

Why is there an IOHandler and an IOEventHandler argument for init?

So wouldn't you set the IOEventHandler directly in the IOHandler as part of initialization? IOW:

struct MyDevice {
    IOHandler iohandler;
};

iohandler.func = my_io_function;
io_handler_init(&iohandler, fd, event_mask);

That's the paradigm I'm used to at least.

Regards,

Anthony Liguori

IOHandler is the object, IOEventHandler is the function call.

Basically this is a 1:1 translation of

class IOHandler {
public:
    IOHandler(int fd, unsigned mask);
    ~IOHandler();
    virtual void io_event_handler() = 0;
    unsigned event_mask();
    void set_event_mask(unsigned mask);
}

class MyClient : private IOHandler {
    virtual void io_event_handler();
}

where the compiler automatically generates the container_of() to get to the actual MyClient pointer.





reply via email to

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