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 upBetter Hololens loop #23904
Better Hololens loop #23904
Conversation
|
@gterzian ignore the clang change and the task change. |
|
I like the new Couple of questions left... |
| HANDLE hEvent = ::OpenEventA(EVENT_ALL_ACCESS, FALSE, sWakeupEvent); | ||
| ::SetEvent(hEvent); | ||
| EnterCriticalSection(&mGLLock); | ||
| mPendingWakeup = true; |
This comment has been minimized.
This comment has been minimized.
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.
This comment has been minimized.
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.
This comment has been minimized.
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.
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.
This comment has been minimized.
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.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| ::SetEvent(hEvent); | ||
| EnterCriticalSection(&mGLLock); | ||
| mLooping = false; | ||
| LeaveCriticalSection(&mGLLock); |
This comment has been minimized.
This comment has been minimized.
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.
This comment has been minimized.
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.
This comment has been minimized.
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.
This comment has been minimized.
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.
This comment has been minimized.
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.
This comment has been minimized.
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.
This comment has been minimized.
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.
This comment has been minimized.
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.
This comment has been minimized.
| ::SetEvent(hEvent); | ||
| EnterCriticalSection(&mGLLock); | ||
| mLooping = false; | ||
| LeaveCriticalSection(&mGLLock); |
This comment has been minimized.
This comment has been minimized.
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.
This comment has been minimized.
|
Also one comment at #23904 (comment) (not sure why some became part of a new review and others not...) |
|
@gterzian I think this can land unless I got something wrong about the |
| ::SetEvent(hEvent); | ||
| EnterCriticalSection(&mGLLock); | ||
| mLooping = false; | ||
| LeaveCriticalSection(&mGLLock); |
This comment has been minimized.
This comment has been minimized.
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.
|
@bors-servo r=gterzian |
|
|
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 retry |
|
|
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 retry |
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 -->
|
|
paulrouget commentedAug 1, 2019
•
edited by SimonSapin
Depends on #23900
Fix #23823
r? @gterzian
This change is