Legend wrote:If it leads to asynch I/O it doesn't seem wrong at all.
True indeed!
Having a lot of unix/x11, and various embedded systems behind me, I prefer making use of message queues rather then registered functions. I find this more intuitive and can also double as an IPC method.
For that reason, communication with my OS will/does consist of sending messages to and from kernel message queues. Communication between threads consists of creating message queues and sending messages to each thread through these queues.
This is just an alteration on your approach... the basic idea is the same.
One crutial point, when using message queues, is using effective messages. I do not enforce a message format, but provide and use a standard format for use inside the OS. This format is similar to the one below (I can't recall it completely offhand):
Code: Select all
typedef struct _Message
{
uint32 messageCategory;
uint32 messageType;
uint32 numParams;
Pointer params[1];
} Message;
Since the message must be allocated at runtime anyway, I allocate a block large enough to contain the exact number of parameters, allowing the message to be of dynamic size with no extra overhead.
The combination of category and type should be enough for anything to accurately classify where this message came from. In other words, an app may choose to have file messages send to one queue, and window messages to another queue... however, it's possible that both get sent to one queue, of course. This is the purpose of category -- a very large scale category -- does this message concern files? memory? window system? sockets? etc.
The type then further defines the category... something such as FileTypeFileOpened, FileTypeSectionRead, FileTypeFileClosed, etc.
Just another option, if you're interested.
Cheers,
Jeff