Hej.
Callbacks are hard to debug and trace.
Message or event queues would be IMO simpler to use.
For every struct (windows, sessions, downloads, connections, etc.)
associate distinct unsigned integer number id,
Every kind of struct would have global counter incremented when
a new struct is allocated.
In the body of messages added to the queue those ids would be used
instead of pointers.
The reverse lookup (id -> pointer) could be done using hashes
or double linked lists. 
When there is no such id in the hash, that's mean that the object
disappeared and the message is ignored.
No more dangling pointers.

There would be two message queues:
when the first one is processed, the new messages are added to the second one.
When the first is cleared, the queues are flipped.

So the main loop could look like this:

for (;;) {
        foreach (message, queue) {
                process(message);
                del(message);
        }
        check_timers();
        select_loop();
        flip_queues();
}

Does it make sense?

Witek
_______________________________________________
elinks-dev mailing list
[email protected]
http://linuxfromscratch.org/mailman/listinfo/elinks-dev

Reply via email to