Many moons ago, while we were frantically trying to make Firefox OS 1.0 run half-decently, I introduced a derived class of nsIRunnable that could be canceled: nsICancelableRunnable. As with many other things that led to the first release of FxOS this was done in a rush and without much thinking. It's only goal at the time was to allow me to cancel a single, simple, stateless runnable that could take a while to run.
Thinking about it afterwards I came to the conclusion that this was a terrible approach: implementing the Cancel() method was up to the user and there was no telling on which threads Run() and Cancel() could be called making it potentially racy. So I thought it could be replaced by adding a Cancel() method to the event queue that would just remove the event in a thread-safe way. This seemed a cleaner, safer approach. But then I looked into our code and discovered that nsICancelableRunnable has spread like a disease through the codebase and it's systematically used in workers to let us cancel events posted to them. Ouch. Some of its uses highlight its problems: in some cases its only purpose is to force calling the Run() method by the calling thread so that certain objects get destroyed on that thread (possibly to prevent leaks). In other cases we have patterns like this: Run() { if (mDoSomething) { DoSomething(); } } Cancel() { mDoSomething = false; } Which is fine if both methods are called by the same thread, but most likely not if they're called on different threads and the interface itself does nothing to prevent you from doing it. All in all I'd still like to get rid of it but I'm not sure if my original approach of moving the cancel functionality into the EventQueue is the right way to go. Which leads me to the point of this e-mail: to gather feedback on my idea to get rid of it. Since I don't have enough knowledge about all the affected areas I'd like to hear from those who actually used it. Gabriele
signature.asc
Description: OpenPGP digital signature
_______________________________________________ dev-platform mailing list dev-platform@lists.mozilla.org https://lists.mozilla.org/listinfo/dev-platform