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 the emulation stop asynchronous to prevent deadlocks. #515

Merged
merged 6 commits into from Jul 10, 2014

Conversation

CrossVR
Copy link
Contributor

@CrossVR CrossVR commented Jun 20, 2014

This PR moves the synchronisation to the last possible moment when we're already certain that the EmuThread has been shut down.

It fixes a potential deadlock where the VideoBackend is waiting for the GUI thread and vice versa. This deadlock seems to only be triggered by exclusive fullscreen, thus this PR is required for PR #506.

This PR has the potential to expose race conditions in code that does not properly check the emulation state so it should be tested thoroughly.

@JMC47
Copy link
Contributor

JMC47 commented Jun 28, 2014

I forgot to say I am in full support of this build. Tons of on close crashes can happen when I'm being stupid.

Actually tested it, none of the normal tricks that have the potential for crashing dolphin work any more. I tried closing while loading a savestate, closing while loading a bad savestate, closing while switching internal resolutions, closing while saving (figured it was worth a try,) closing with the button and escape at the same time.

Honestly, it seems rock solid. Even if there are problems with this, I'm guessing it fixes more than it breaks.

@CrossVR
Copy link
Contributor Author

CrossVR commented Jun 28, 2014

@JMC47 That means there were probably more components than just the VideoBackend that would deadlock if the GUI thread is blocked.

@CrossVR
Copy link
Contributor Author

CrossVR commented Jun 28, 2014

To prevent potential problems we should probably disable much of the user interface while we're in the CORE_STOPPING state.

For now I've added functionality to update the GUI and disable the play button to show the stopping state.

@lioncash
Copy link
Member

Looks good to me

@JMC47
Copy link
Contributor

JMC47 commented Jul 8, 2014

I did not notice any regressions while testing. Hopefully it can be merged so that work continues on exclusive fullscreen.

There's only so much I can test for closing the emulator.

@@ -81,4 +82,8 @@ void UpdateTitle();
// the return value of the first call should be passed in as the second argument of the second call.
bool PauseAndLock(bool doLock, bool unpauseOnUnlock=true);

// for calling back into UI code without introducing a dependency on it in core
typedef void(*CallbackFunc)(void);

This comment was marked as off-topic.

This comment was marked as off-topic.

@neobrain
Copy link
Member

neobrain commented Jul 8, 2014

Welp.. I'd be happier if the whole startup/shutdown code were just rewritten from scratch, but since the net effect of this branch seems to be fixing a lot of dumb crashes rather than introducing new instabilities, it's fine with me.

Other than the comments I added, LGTM.

@@ -83,6 +83,7 @@ bool g_bStarted = false;
void *g_pWindowHandle = nullptr;
std::string g_stateFileName;
std::thread g_EmuThread;
static CallbackFunc g_onAfterStopCb = nullptr;

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This may expose bugs which relied on the Main Thread to be suspended in the stopping state.
…lized.

This properly handles the stopping state and more accurately represents the intended check.
…ted yet.

Fixes a null pointer exception when the user starts the recording during a state transition.
@neobrain
Copy link
Member

neobrain commented Jul 9, 2014

What has changed in the new series of commits? Was it just addressing review comments?

@CrossVR
Copy link
Contributor Author

CrossVR commented Jul 9, 2014

@neobrain Sorry about that, I addressed your comments and I updated some more state checks in the db7e746 commit. If you could do another review of that commit it'd be great.

And I think commit 4df00ae should probably be cherry-picked for PR #587, it was something I found during my search for state checks but it is more relevant for that PR than this one.

@neobrain
Copy link
Member

neobrain commented Jul 9, 2014

@Armada651: This comment grants you the permission to merge this pull request whenever you think it is ready. After addressing the remaining comments, click this link to merge.


If all you did was addressing my comments and adding more stability, this should be fine to merge. Well, your call anyway ;)

@dolphin-emu-bot allowmerge

@CrossVR
Copy link
Contributor Author

CrossVR commented Jul 10, 2014

@dolphin-emu-bot rebuild

dolphin-emu-bot added a commit that referenced this pull request Jul 10, 2014
Make the emulation stop asynchronous to prevent deadlocks.
@dolphin-emu-bot dolphin-emu-bot merged commit bc655d1 into dolphin-emu:master Jul 10, 2014
@CrossVR CrossVR deleted the threading branch July 10, 2014 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
5 participants