Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Java measure thread-safe. #60

Merged
merged 1 commit into from
Mar 27, 2015
Merged

Make Java measure thread-safe. #60

merged 1 commit into from
Mar 27, 2015

Conversation

tcmulcahy
Copy link

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.

@vjeux
Copy link
Contributor

vjeux commented Mar 23, 2015

@kmagiera or @astreet can you review this?

*/
package com.facebook.csslayout;

public class CSSLayoutContext {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add short class level comment explaining what is this for

@kmagiera
Copy link
Contributor

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.

@tcmulcahy
Copy link
Author

Okay, I've added the javadoc, and also fixed a long line.

kmagiera added a commit that referenced this pull request Mar 27, 2015
@kmagiera kmagiera merged commit cf3f7cc into facebook:master Mar 27, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants