1
0
mirror of https://github.com/cathery/sys-con.git synced 2024-06-29 00:48:43 +00:00

Add a scoped lock for controller handler

This commit is contained in:
cathery 2020-04-17 12:05:32 +03:00
parent a00188868c
commit 8434a9e250
4 changed files with 15 additions and 0 deletions

View File

@ -14,6 +14,7 @@ namespace syscon::controllers
constexpr size_t MaxControllerHandlersSize = 10;
std::vector<std::unique_ptr<SwitchVirtualGamepadHandler>> controllerHandlers;
bool UseAbstractedPad;
ams::os::Mutex controllerMutex;
}
bool IsAtControllerLimit()
@ -37,7 +38,10 @@ namespace syscon::controllers
Result rc = switchHandler->Initialize();
if (R_SUCCEEDED(rc))
{
std::scoped_lock scoped_lock(controllerMutex);
controllerHandlers.push_back(std::move(switchHandler));
}
return rc;
}
@ -46,6 +50,11 @@ namespace syscon::controllers
{
return controllerHandlers;
}
ams::os::Mutex& GetScopedLock()
{
return controllerMutex;
}
/*
void Remove(std::function func)
{
@ -61,6 +70,7 @@ namespace syscon::controllers
void Reset()
{
std::scoped_lock scoped_lock(controllerMutex);
controllerHandlers.clear();
}

View File

@ -2,6 +2,7 @@
#include "ControllerHelpers.h"
#include "SwitchVirtualGamepadHandler.h"
#include <stratosphere.hpp>
namespace syscon::controllers
{
@ -9,6 +10,7 @@ namespace syscon::controllers
Result Insert(std::unique_ptr<IController> &&controllerPtr);
std::vector<std::unique_ptr<SwitchVirtualGamepadHandler>>& Get();
ams::os::Mutex& GetScopedLock();
//void Remove(void Remove(bool (*func)(std::unique_ptr<SwitchVirtualGamepadHandler> a)));;

View File

@ -36,6 +36,7 @@ namespace syscon::psc
case PscPmState_ReadySleep:
case PscPmState_ReadyShutdown:
usb::DestroyUsbEvents();
controllers::Reset();
break;
default:
break;

View File

@ -119,6 +119,8 @@ namespace syscon::usb
WriteToLog("Interface state was changed");
std::scoped_lock usbLock(usbMutex);
std::scoped_lock controllersLock(controllers::GetScopedLock());
eventClear(usbHsGetInterfaceStateChangeEvent());
memset(interfaces, 0, sizeof(interfaces));
if (R_SUCCEEDED(usbHsQueryAcquiredInterfaces(interfaces, sizeof(interfaces), &total_entries)))