Make Java measure thread-safe. #60
Reference in New Issue
Block a user
No description provided.
Delete Branch "thread-safe-measure"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The measure method in java previously referenced a global MEASURE_OUTPUT variable. This means that css layout could not be done safely from multiple threads. The naive solution would be to create a MeasureOutput on each measure invocation, but since Android is sensitive to allocation and garbage collection, we instead force a MeasureOutput instance to be passed in to calculateLayout. Since it would be strange and non-intuitive to pass MeasureOutput to calculateLayout, this implementation detail is hidden from clients by wrapping the MeasureOutput in a CSSLayoutContext object. Clients are free to re-use the same CSSLayoutContext object, provided that they ensure it is not used concurrently from multiple threads.
@kmagiera or @astreet can you review this?
Thanks! Looks good, please just add a class level comment to CSSLayoutContext that will explain the purpose of this class and that a separate instance should be used when calculateLayout is called concurrently for different node hierarchies.
Okay, I've added the javadoc, and also fixed a long line.