Replace balanced Core::PauseAndLock calls with RunAsCPUThread
Core::PauseAndLock requires all calls to it to be balanced, like this:
const bool was_unpaused = Core::PauseAndLock(true);
// do stuff on the CPU thread
Core::PauseAndLock(false, was_unpaused);
Aside from being a bit cumbersome, it turns out all callers really
don't need to know about was_unpaused at all. They just need to do
something on the CPU thread safely, including locking/unlocking.
So this commit replaces Core::PauseAndLock with a function that
makes both the purpose and the scope of what is being run on the
CPU thread visually clear. This makes it harder to accidentally run
something on the wrong thread, or forget the second call to
PauseAndLock to unpause, or forget that it needs to be passed
was_unpaused at the end.
We also don't need comments to indicate code X is being run on the
CPU thread anymore, as the function name makes it obvious.
This commit is contained in:
1 parent
2f0bec93cb
commit
f106a9637d
13 files changed
+300
-317
No files matched your search
@@ -74,12 +74,14 @@ void RequestRefreshInfo();
|
||||
|
||||
void UpdateTitle();
|
||||
|
||||
// waits until all systems are paused and fully idle, and acquires a lock on that state.
|
||||
// or, if doLock is false, releases a lock on that state and optionally unpauses.
|
||||
// calls must be balanced (once with doLock true, then once with doLock false) but may be recursive.
|
||||
// the return value of the first call should be passed in as the second argument of the second call.
|
||||
// [NOT THREADSAFE] Host only
|
||||
bool PauseAndLock(bool doLock, bool unpauseOnUnlock = true);
|
||||
// Run a function as the CPU thread.
|
||||
//
|
||||
// If called from the Host thread, the CPU thread is paused and the current thread temporarily
|
||||
// becomes the CPU thread while running the function.
|
||||
// If called from the CPU thread, the function will be run directly.
|
||||
//
|
||||
// This should only be called from the CPU thread or the host thread.
|
||||
void RunAsCPUThread(std::function<void()> function);
|
||||
|
||||
// for calling back into UI code without introducing a dependency on it in core
|
||||
using StoppedCallbackFunc = std::function<void()>;
|
||||
|
||||
Reference in new issue
Block a user