The landing of bugs 58904 and 456272 have brought a new synchronization API to the Mozilla platform. I think I’m safe in saying that the old API (
nsAutoLock, and friends) is deprecated in favor of the new. But this is a good thing; you’ll prefer the new one, trust me.
We’ve improved the API in the following ways
- all classes are in the
- the “bare” primitives (
CondVar) can now be allocated on the stack or as direct class members. Their constructors use a proto-non-failing
malloc, so your code will never see out-of-memory errors.
- the primitives and their RAII wrappers (
MonitorAutoEnter) provide methods to assert that the primitive is “owned,” or not, by the currently executing thread. These should be used liberally in your code to enforce locking invariants (the assertions disappear in optimized builds).
- the deadlock detector used by the new primitives in debug builds is asymptotically (and practically) more efficient than the old, should catch more deadlocks, and is now thread safe (!).
As with any change to core APIs, this one will require a lot of rewriting. We’ll keep the old one around for a while, but new patches should use the new API. (Aside: Shawn Wilsher has been an early adopter, for the storage code. Check out what he’s been doing for some real-world examples.)
We’ve been extending our static analysis/refactoring tools to make upgrading old code easier. Hopefully, few people will need to worry about this. I’ll soon be blogging about our work; I think it’s a good example of how sweeping changes to existing code can be done quite easily, by one or two guys, in a matter of weeks.
The main change to the API that may cause some consternation is the removal of the
nsAutoMonitor::Enter/Exit methods from
MonitorAutoEnter. It has been decreed that they are bad news. Unfortunately, these are fairly difficult to rewrite automatically, so we may need to recruit a few module owners to help out.
Most of the new API is documented on MDC. But please ping
cjones on IRC if you have more questions or concerns.
[EDIT I see from PMO that I should be h4 and below.]