Windows: Prevent hang on shutdown.

Which may occur on ARM64 or perhaps lower thread processors?  Let's avoid
spinloops.
This commit is contained in:
Unknown W. Brackets committed 2021-01-02 22:49:06 -08:00
1 parent 83272c5e25
commit c66d5dcac1
3 files changed
+22 -6

No files matched your search

+2 -4
View File
@@ -946,14 +946,12 @@ void NativeShutdownGraphics() {
#if PPSSPP_PLATFORM(WINDOWS) && !PPSSPP_PLATFORM(UWP)
if (winCamera) {
winCamera->sendMessage({ CAPTUREDEVIDE_COMMAND::SHUTDOWN, nullptr });
while (!winCamera->isShutDown()) {};// Wait for shutting down.
winCamera->waitShutDown();
delete winCamera;
winCamera = nullptr;
}
if (winMic) {
winMic->sendMessage({ CAPTUREDEVIDE_COMMAND::SHUTDOWN, nullptr });
while (!winMic->isShutDown()) {};// Wait for shutting down.
winMic->waitShutDown();
delete winMic;
winMic = nullptr;
}
+15
View File
@@ -854,6 +854,21 @@ CAPTUREDEVIDE_MESSAGE WindowsCaptureDevice::getMessage() {
return message;
}
void WindowsCaptureDevice::updateState(const CAPTUREDEVIDE_STATE &newState) {
std::unique_lock<std::mutex> guard(stateMutex_);
state = newState;
stateCond_.notify_all();
}
void WindowsCaptureDevice::waitShutDown() {
sendMessage({ CAPTUREDEVIDE_COMMAND::SHUTDOWN, nullptr });
std::unique_lock<std::mutex> guard(stateMutex_);
while (!isShutDown()) {
stateCond_.wait(guard);
}
}
void WindowsCaptureDevice::messageHandler() {
CoInitializeEx(NULL, COINIT_MULTITHREADED);
MFStartup(MF_VERSION);
+5 -2
View File
@@ -194,11 +194,11 @@ public:
void setError(const CAPTUREDEVIDE_ERROR &newError, const std::string &newErrorMessage) { error = newError; errorMessage = newErrorMessage; }
void setSelction(const UINT32 &selection) { param.selection = selection; }
void updateState(const CAPTUREDEVIDE_STATE &newState) { state = newState; }
HRESULT setDeviceParam(IMFMediaType *pType);
bool isShutDown() const { return state == CAPTUREDEVIDE_STATE::SHUTDOWN; }
bool isStarted() const { return state == CAPTUREDEVIDE_STATE::STARTED; }
void waitShutDown();
void sendMessage(CAPTUREDEVIDE_MESSAGE message);
CAPTUREDEVIDE_MESSAGE getMessage();
@@ -210,7 +210,8 @@ public:
friend class ReaderCallback;
protected:
// Handle message here.
void updateState(const CAPTUREDEVIDE_STATE &newState);
// Handle message here.
void messageHandler();
CAPTUREDEVIDE_TYPE type;
@@ -239,6 +240,8 @@ protected:
// Param updating synchronously.
std::mutex paramMutex;
std::mutex stateMutex_;
std::condition_variable stateCond_;
// Camera only
unsigned char *imageRGB = nullptr;