Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upConstellation manages script thread lifetime #14052
Conversation
highfive
commented
Nov 3, 2016
|
Heads up! This PR modifies the following files:
|
highfive
commented
Nov 3, 2016
9ac6e4d
to
774172b
|
Rebased. |
|
Could you write in the second commit message why switching to a set of documents was needed? |
| self.offset = self.offset + 1; | ||
| result | ||
| } | ||
| } |
This comment has been minimized.
This comment has been minimized.
nox
Nov 4, 2016
Member
Why do you need this iterator? We shouldn't use NodeList outside from other DOM stuff IMO, it's quite inefficient.
Also, this iterator continues to increment offset for nothing if self.nodes.Item(self.offset) returned None, and it doesn't provide a size hint so it's probably used inefficiently.
| }, | ||
| DevtoolScriptControlMsg::GetRootNode(id, reply) => | ||
| devtools::handle_get_root_node(&context, id, reply), | ||
| devtools::handle_get_root_node(&*documents, id, reply), |
This comment has been minimized.
This comment has been minimized.
| pub struct ScriptChan { | ||
| chan: IpcSender<ConstellationControlMsg>, | ||
| dont_send_or_sync: PhantomData<Rc<()>>, | ||
| } |
This comment has been minimized.
This comment has been minimized.
nox
Nov 4, 2016
Member
This seems quite dangerous to me. Could we not rely on Drop? What happens if that value is forgotten?
This comment has been minimized.
This comment has been minimized.
jdm
Nov 7, 2016
Member
I disagree that it seems dangerous, but I don't understand why it's needed. Whether it's Sync or not seems immaterial, since we just seem to care that ownership can't be transferred to some non-constellation thread. However, if it's only constructed via the new method and that only returns Rc, this seems to be redundant.
This comment has been minimized.
This comment has been minimized.
asajeffrey
Nov 8, 2016
Author
Member
The dont_send_or_sync isn't necessary, it's just there to make sure that any messages that are sent on this channel come from the constellation thread. I could just remove it.
774172b
to
354501b
|
r? @jdm |
| debug!("Exiting script thread."); | ||
|
|
||
| while let Some(pipeline_id) = self.incomplete_loads.borrow().iter().next().map(|load| load.pipeline_id) | ||
| .or_else(|| self.documents.borrow().iter().next().map(|doc| doc.global().pipeline_id())) |
This comment has been minimized.
This comment has been minimized.
jdm
Nov 7, 2016
Member
let mut pipelines = self.incomplete_loads.borrow().iter().map(|load| load.pipeline_id);
let mut pipelines = self.documents.borrow().iter().map(|doc| doc.global().pipeline_id()).zip(pipelines);
while let Some(pipeline_id) = pipelines.next() {Also, if we add the ability to iterate over the keys of the documents object, the second iterator becomes clearer.
This comment has been minimized.
This comment has been minimized.
asajeffrey
Nov 8, 2016
Author
Member
The problem is we can't have the iterator borrowed while we call handle_exit_pipeline_msg, since it mutably borrows self.documents and self.incomplete_loads.
This comment has been minimized.
This comment has been minimized.
jdm
Nov 8, 2016
Member
I'm actually surprised that this works as written, since calling iter() should cause a new iterator to be created every time...
This comment has been minimized.
This comment has been minimized.
jdm
Nov 8, 2016
Member
A more workable option is to create a vector from the original iterators and iterate over that.
This comment has been minimized.
This comment has been minimized.
asajeffrey
Nov 8, 2016
Author
Member
There is new iterator each time, but that's okay because handle_exit_pipeline_msg removes the entry, so we don't end up infinitely looping. We can just collect the iterators into a vector though, that is probably easier to read.
| pub fn send(&self, msg: ConstellationControlMsg) -> Result<(), IOError> { | ||
| self.chan.send(msg) | ||
| } | ||
| pub fn new(chan: IpcSender<ConstellationControlMsg>) -> ScriptChan { |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| pub struct ScriptChan { | ||
| chan: IpcSender<ConstellationControlMsg>, | ||
| dont_send_or_sync: PhantomData<Rc<()>>, | ||
| } |
This comment has been minimized.
This comment has been minimized.
jdm
Nov 7, 2016
Member
I disagree that it seems dangerous, but I don't understand why it's needed. Whether it's Sync or not seems immaterial, since we just seem to care that ownership can't be transferred to some non-constellation thread. However, if it's only constructed via the new method and that only returns Rc, this seems to be redundant.
|
|
354501b
to
7624ea7
|
Looks good! |
d27a481
to
08effa7
|
Squashed. @bors-servo r=jdm |
|
|
08effa7
to
0e7ffaf
|
@bors-servo r=jdm |
|
|
…-lifetime, r=jdm Constellation manages script thread lifetime <!-- Please describe your changes on the following line: --> Yet another step towards fixing #633... At the moment, script threads are responsible for killing themselves when they have no more pipelines to manage. This is fine right now, because script threads have a root pipeline: once it is closed, everything is closed. It's not fine once we fix #633 because there's a race condition where the constellation could kill the last pipeline in a script thread, then open a new one in the same script thread. We can't have the constellation block on the script thread, waiting to make sure a pipeline is created, since this could introduce deadlock. The easiest solution is to have the constellation manage the script thread lifetime: when the constellation discovers that a script thread is not managing any live pipelines, it closes the script thread, and updates its own state. Most of the commits are from #14013, its just "Script thread lifetime is now managed by the constellation." (9ac6e4d) that's new. cc @jdm @ConnorGBrewster --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes do not require tests because refactoring <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14052) <!-- Reviewable:end -->
|
|
asajeffrey commentedNov 3, 2016
•
edited by larsbergstrom
Yet another step towards fixing #633...
At the moment, script threads are responsible for killing themselves when they have no more pipelines to manage. This is fine right now, because script threads have a root pipeline: once it is closed, everything is closed. It's not fine once we fix #633 because there's a race condition where the constellation could kill the last pipeline in a script thread, then open a new one in the same script thread.
We can't have the constellation block on the script thread, waiting to make sure a pipeline is created, since this could introduce deadlock. The easiest solution is to have the constellation manage the script thread lifetime: when the constellation discovers that a script thread is not managing any live pipelines, it closes the script thread, and updates its own state.
Most of the commits are from #14013, its just "Script thread lifetime is now managed by the constellation." (9ac6e4d) that's new.
cc @jdm @ConnorGBrewster
./mach build -ddoes not report any errors./mach test-tidydoes not report any errorsThis change is