mirror of
https://github.com/cathery/sys-con.git
synced 2025-02-11 06:40:26 +00:00
Add a scoped lock for controller handler
This commit is contained in:
parent
a00188868c
commit
8434a9e250
@ -14,6 +14,7 @@ namespace syscon::controllers
|
|||||||
constexpr size_t MaxControllerHandlersSize = 10;
|
constexpr size_t MaxControllerHandlersSize = 10;
|
||||||
std::vector<std::unique_ptr<SwitchVirtualGamepadHandler>> controllerHandlers;
|
std::vector<std::unique_ptr<SwitchVirtualGamepadHandler>> controllerHandlers;
|
||||||
bool UseAbstractedPad;
|
bool UseAbstractedPad;
|
||||||
|
ams::os::Mutex controllerMutex;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsAtControllerLimit()
|
bool IsAtControllerLimit()
|
||||||
@ -37,7 +38,10 @@ namespace syscon::controllers
|
|||||||
|
|
||||||
Result rc = switchHandler->Initialize();
|
Result rc = switchHandler->Initialize();
|
||||||
if (R_SUCCEEDED(rc))
|
if (R_SUCCEEDED(rc))
|
||||||
|
{
|
||||||
|
std::scoped_lock scoped_lock(controllerMutex);
|
||||||
controllerHandlers.push_back(std::move(switchHandler));
|
controllerHandlers.push_back(std::move(switchHandler));
|
||||||
|
}
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
@ -46,6 +50,11 @@ namespace syscon::controllers
|
|||||||
{
|
{
|
||||||
return controllerHandlers;
|
return controllerHandlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ams::os::Mutex& GetScopedLock()
|
||||||
|
{
|
||||||
|
return controllerMutex;
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
void Remove(std::function func)
|
void Remove(std::function func)
|
||||||
{
|
{
|
||||||
@ -61,6 +70,7 @@ namespace syscon::controllers
|
|||||||
|
|
||||||
void Reset()
|
void Reset()
|
||||||
{
|
{
|
||||||
|
std::scoped_lock scoped_lock(controllerMutex);
|
||||||
controllerHandlers.clear();
|
controllerHandlers.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "ControllerHelpers.h"
|
#include "ControllerHelpers.h"
|
||||||
#include "SwitchVirtualGamepadHandler.h"
|
#include "SwitchVirtualGamepadHandler.h"
|
||||||
|
#include <stratosphere.hpp>
|
||||||
|
|
||||||
namespace syscon::controllers
|
namespace syscon::controllers
|
||||||
{
|
{
|
||||||
@ -9,6 +10,7 @@ namespace syscon::controllers
|
|||||||
|
|
||||||
Result Insert(std::unique_ptr<IController> &&controllerPtr);
|
Result Insert(std::unique_ptr<IController> &&controllerPtr);
|
||||||
std::vector<std::unique_ptr<SwitchVirtualGamepadHandler>>& Get();
|
std::vector<std::unique_ptr<SwitchVirtualGamepadHandler>>& Get();
|
||||||
|
ams::os::Mutex& GetScopedLock();
|
||||||
|
|
||||||
//void Remove(void Remove(bool (*func)(std::unique_ptr<SwitchVirtualGamepadHandler> a)));;
|
//void Remove(void Remove(bool (*func)(std::unique_ptr<SwitchVirtualGamepadHandler> a)));;
|
||||||
|
|
||||||
|
@ -36,6 +36,7 @@ namespace syscon::psc
|
|||||||
case PscPmState_ReadySleep:
|
case PscPmState_ReadySleep:
|
||||||
case PscPmState_ReadyShutdown:
|
case PscPmState_ReadyShutdown:
|
||||||
usb::DestroyUsbEvents();
|
usb::DestroyUsbEvents();
|
||||||
|
controllers::Reset();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -119,6 +119,8 @@ namespace syscon::usb
|
|||||||
WriteToLog("Interface state was changed");
|
WriteToLog("Interface state was changed");
|
||||||
|
|
||||||
std::scoped_lock usbLock(usbMutex);
|
std::scoped_lock usbLock(usbMutex);
|
||||||
|
std::scoped_lock controllersLock(controllers::GetScopedLock());
|
||||||
|
|
||||||
eventClear(usbHsGetInterfaceStateChangeEvent());
|
eventClear(usbHsGetInterfaceStateChangeEvent());
|
||||||
memset(interfaces, 0, sizeof(interfaces));
|
memset(interfaces, 0, sizeof(interfaces));
|
||||||
if (R_SUCCEEDED(usbHsQueryAcquiredInterfaces(interfaces, sizeof(interfaces), &total_entries)))
|
if (R_SUCCEEDED(usbHsQueryAcquiredInterfaces(interfaces, sizeof(interfaces), &total_entries)))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user