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

Better Hololens loop #23904

Merged
merged 2 commits into from Aug 7, 2019
Merged

Better Hololens loop #23904

merged 2 commits into from Aug 7, 2019

Conversation

@paulrouget
Copy link
Contributor

paulrouget commented Aug 1, 2019

Depends on #23900

Fix #23823

r? @gterzian


This change is Reviewable

@paulrouget
Copy link
Contributor Author

paulrouget commented Aug 1, 2019

@gterzian ignore the clang change and the task change.

Copy link
Member

gterzian left a comment

I like the new task() part!

Couple of questions left...

HANDLE hEvent = ::OpenEventA(EVENT_ALL_ACCESS, FALSE, sWakeupEvent);
::SetEvent(hEvent);
EnterCriticalSection(&mGLLock);
mPendingWakeup = true;

This comment has been minimized.

@gterzian

gterzian Aug 1, 2019

Member

How about just doing RunOnGLThread([=] { });, so that the flag can be removed?

Later it could also be a hook to provide a specific event to WakeUp(), where the match would happen here and the "right" task would be added to the queue?

This comment has been minimized.

@gterzian

gterzian Aug 1, 2019

Member

If you use RunOnGLThread([=] { }), you don't need to use the critical section and wake stuff here(even though I think they are actually re-entrant so it wouldn't deadlock, but still...)

This comment has been minimized.

@paulrouget

paulrouget Aug 1, 2019

Author Contributor

That what I was initially doing. Just felt like capturing the closure context on WakeUp was an unnecessary overhead. But it's probably minimal. For the sake of simplicity I might get rid of mPendingWakeup.

This comment has been minimized.

@@ -488,7 +488,8 @@ impl ServoGlue {
.host_callbacks
.on_allow_navigation(url.to_string());
let window_event = WindowEvent::AllowNavigationResponse(pipeline_id, data);
let _ = self.process_event(window_event);
self.events.push(window_event);

This comment has been minimized.

@gterzian

gterzian Aug 1, 2019

Member

Perhaps add a FIXME here to say that this would ideally go through host_callbacks?

This comment has been minimized.

@paulrouget

paulrouget Aug 1, 2019

Author Contributor

What do you mean go through host_callbacks?

This comment has been minimized.

@gterzian

gterzian Aug 2, 2019

Member

If we wanted to actually ask the user for permission, it would have to go through there, right?

This comment has been minimized.

@jdm

jdm Aug 2, 2019

Member

Isn't that what's happening two lines earlier?

This comment has been minimized.

@gterzian

gterzian Aug 2, 2019

Member

Oops...

::SetEvent(hEvent);
EnterCriticalSection(&mGLLock);
mLooping = false;
LeaveCriticalSection(&mGLLock);

This comment has been minimized.

@gterzian

gterzian Aug 1, 2019

Member

Here you might also need to add a WakeConditionVariable(&mGLCondVar);, to make sure the loop wakes-up and sees the change.

This comment has been minimized.

@paulrouget

paulrouget Aug 1, 2019

Author Contributor

That should not be necessary as we know that at the point that we are not waiting on the variable.

This comment has been minimized.

@gterzian

gterzian Aug 2, 2019

Member

I'm not sure I understand the flow then.

If mTasks.size() == 0 && !mAnimating && mLooping, the loop might be waiting on the condvar. In that case it won't see the change of mLooping = false unless woken-up.

And RequestShutdown doesn't seem to do anything to ensure it is not waiting by the time OnShutdownComplete is called.

This comment has been minimized.

@gterzian

gterzian Aug 2, 2019

Member

Since RequestShutdown is called at https://github.com/servo/servo/pull/23904/files#diff-9f1e08fa0c4bb110f99fabbfeb609314R40, which is when mLooping, so then when OnShutdownComplete is called by Servo, mLooping would still be true, which means unless there are events or it's animating, it could be waiting, then here it is to false, and for the loop to stop it would need wake-up and see the change to !mLooping?

This comment has been minimized.

@paulrouget

paulrouget Aug 5, 2019

Author Contributor

the loop might be waiting on the condvar

No because at that point we are running code in the compositor thread. OnShutdownComplete is called from perform_update. It's impossible to be waiting on the condvar at that point.

so after OnShutdownComplete is called, perform_udpate finishes, we get back to the beginning of the loop, mLooping is checked. And we good :)

This comment has been minimized.

@gterzian

gterzian Aug 5, 2019

Member

Yep I think you're right, inside mServo->PerformUpdates() it's set to false, and then you go back to the top and you don't wait, going straight to break.

looks good.

::WaitForSingleObject(hEvent, INFINITE);
StopRenderLoop();
RunOnGLThread([=] { mServo->RequestShutdown(); });
mLoopTask->wait();

This comment has been minimized.

@gterzian

gterzian Aug 1, 2019

Member

Is this basically going to wait on cancel_current_task() to be called from inside the loop?

Since that will eventually happen as a result of the OnShutdownComplete call.

And OnShutdownComplete will not signal back here, so if this here will be notified once the loop stops, it looks right, otherwise you might want to keep the sShutdownEvent, and dispatch it when the loop stops.

This comment has been minimized.

@paulrouget

paulrouget Aug 1, 2019

Author Contributor

Is this basically going to wait on cancel_current_task() to be called from inside the loop?

Yes.

sShutdownEvent is not necessary. Wait() will block until the loop stops, and will stop only if OnShutdownComplete is called.

This comment has been minimized.

@paulrouget paulrouget changed the title [wip] Better Hololens loop Better Hololens loop Aug 1, 2019
@paulrouget paulrouget force-pushed the paulrouget:loop2 branch from 70a9658 to 20c7692 Aug 1, 2019
::SetEvent(hEvent);
EnterCriticalSection(&mGLLock);
mLooping = false;
LeaveCriticalSection(&mGLLock);

This comment has been minimized.

@gterzian

gterzian Aug 2, 2019

Member

I'm not sure I understand the flow then.

If mTasks.size() == 0 && !mAnimating && mLooping, the loop might be waiting on the condvar. In that case it won't see the change of mLooping = false unless woken-up.

And RequestShutdown doesn't seem to do anything to ensure it is not waiting by the time OnShutdownComplete is called.

::WaitForSingleObject(hEvent, INFINITE);
StopRenderLoop();
RunOnGLThread([=] { mServo->RequestShutdown(); });
mLoopTask->wait();

This comment has been minimized.

@gterzian
Copy link
Member

gterzian commented Aug 2, 2019

Also one comment at #23904 (comment) (not sure why some became part of a new review and others not...)

@paulrouget
Copy link
Contributor Author

paulrouget commented Aug 5, 2019

@gterzian I think this can land unless I got something wrong about the OnShutdownComplete bit.

::SetEvent(hEvent);
EnterCriticalSection(&mGLLock);
mLooping = false;
LeaveCriticalSection(&mGLLock);

This comment has been minimized.

@gterzian

gterzian Aug 5, 2019

Member

Yep I think you're right, inside mServo->PerformUpdates() it's set to false, and then you go back to the top and you don't wait, going straight to break.

looks good.

@paulrouget
Copy link
Contributor Author

paulrouget commented Aug 5, 2019

@bors-servo r=gterzian

@bors-servo
Copy link
Contributor

bors-servo commented Aug 5, 2019

📌 Commit 20c7692 has been approved by gterzian

@bors-servo
Copy link
Contributor

bors-servo commented Aug 5, 2019

Testing commit 20c7692 with merge e76c880...

bors-servo added a commit that referenced this pull request Aug 5, 2019
Better Hololens loop

Depends on #23900

Fix #23823

r? @gterzian

<!-- 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/23904)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Aug 5, 2019

💔 Test failed - linux-rel-wpt

@CYBAI
Copy link
Collaborator

CYBAI commented Aug 5, 2019

@bors-servo
Copy link
Contributor

bors-servo commented Aug 5, 2019

💣 Failed to start rebuilding: Unknown error

@bors-servo
Copy link
Contributor

bors-servo commented Aug 5, 2019

Testing commit 20c7692 with merge a1a07f4...

bors-servo added a commit that referenced this pull request Aug 5, 2019
Better Hololens loop

Depends on #23900

Fix #23823

r? @gterzian

<!-- 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/23904)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Aug 5, 2019

💔 Test failed - linux-rel-wpt

@paulrouget
Copy link
Contributor Author

paulrouget commented Aug 7, 2019

@bors-servo retry

@bors-servo
Copy link
Contributor

bors-servo commented Aug 7, 2019

Testing commit 20c7692 with merge 371f514...

bors-servo added a commit that referenced this pull request Aug 7, 2019
Better Hololens loop

Depends on #23900

Fix #23823

r? @gterzian

<!-- 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/23904)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Aug 7, 2019

☀️ Test successful - linux-rel-css, linux-rel-wpt, status-taskcluster
Approved by: gterzian
Pushing 371f514 to master...

@bors-servo bors-servo merged commit 20c7692 into servo:master Aug 7, 2019
3 checks passed
3 checks passed
Taskcluster (pull_request) TaskGroup: success
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
homu Test successful
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

6 participants
You can’t perform that action at this time.