Repository navigation
Make SharedLayoutContext threadsafe. - #7524
eefriedman wants to merge 1 commit into
Conversation
1c8114f to
1d17d86
Compare
|
r? @pcwalton |
There was a problem hiding this comment.
Please pass the mutex along here. It'll be too slow otherwise.
1d17d86 to
8982fe4
Compare
|
Figured out how to avoid the Stylist locking. Current version is WIP; but I'd like to double-check that the approach is sane. |
6d5244a to
a293c79
Compare
|
Updated. Not sure why I thought the other stuff needed mutexes; I was probably just confused by the comment claiming they do. |
|
☔ The latest upstream changes (presumably #7613) made this pull request unmergeable. Please resolve the merge conflicts. |
a293c79 to
c900824
Compare
|
☔ The latest upstream changes (presumably #7644) made this pull request unmergeable. Please resolve the merge conflicts. |
c900824 to
b385969
Compare
|
Updated version. Rebased, and fixed so it adds zero new mutexes. |
|
☔ The latest upstream changes (presumably #7710) made this pull request unmergeable. Please resolve the merge conflicts. |
|
(I'm not planning to rebase this again until it gets reviewed.) |
There was a problem hiding this comment.
What does "Frozen"/"Unfrozen" mean? I'm a bit confused. Is "Frozen" immutable? If so, that would be called "Sync" in Rust.
There was a problem hiding this comment.
Frozen probably isn't the best terminology, but I was having trouble thinking of something better.
When we do layout, we have to build a SharedLayoutContext. To avoid extraneous locking/copying, it needs to have a pointer into the current LayoutTaskData. (There's probably more unnecessary copying that could be avoided as a followup, but I wanted to keep this from getting too complicated.) However, some bits need to be mutated while the SharedLayoutContext exists. So this patch splits LayoutTaskData into the bits which are immutably borrowed by SharedLayoutContext and the bits which need to be mutated. The "frozen" section is the one which is borrowed, and therefore can't be mutated.
b385969 to
1086c59
Compare
|
Updated. Forgot a Sync bound in WorkQueue, so I managed to confuse myself about Sender (which in practice is Sync, but doesn't expose a Sync bound; see rust-lang/rfcs#1299 .) Renamed the usage of Frozen to Sync, which is essentially appropriate here given that SharedLayoutContext is Sync. |
Making the Stylist usage threadsafe without unsafe code or extra locking required some changes to WorkQueue; the changes are mostly straightforward. Some refactoring of LayoutTaskData was also required: this is basically just splitting the structure in two so the borrow checker can understand that building a SharedLayoutContext only borrows part of LayoutTaskData. The "frozen" part is the part that can't be safely modified while a parallel work-queue is running. It might be worth considering switching to some sort of threadsafe channel to avoid the mutexes... see Rust RFC PR servo#1299. Fixes servo#2604. Pretty sure the issue with the other version mentioned there was just that it held on to the lock too long.
1086c59 to
e11c00a
Compare
|
☔ The latest upstream changes (presumably #7423) made this pull request unmergeable. Please resolve the merge conflicts. |
|
This seems fine to me in general. I'm a little worried about performance of the font cache task mutex, but if it's measured to be not a problem then I'm fine with it. |
I'm not sure how this could be an issue... each layout thread takes the lock exactly once in its entire lifetime. |
|
Oh, OK then. In that case looks good after a rebase. |
|
Fwiw, I'd like to have this wait a bit; I'm looking into an alternative approach. |
|
Okay. I might try to split out the WorkQueue-related changes into a separate PR, since they're probably useful anyway. |
|
Any updates? |
|
I'll revisit this once #9050 is resolved, I guess. |
Not sure if this is the best way to structure the code; there are a lot
of mutexes involved.
Fixes #2604. Pretty sure the issue with the other version mentioned
there was just that it held on to the lock too long.