mirror of
https://github.com/cathery/sys-con.git
synced 2025-02-06 00:39:57 +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;
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -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)));;
|
||||
|
||||
|
@ -36,6 +36,7 @@ namespace syscon::psc
|
||||
case PscPmState_ReadySleep:
|
||||
case PscPmState_ReadyShutdown:
|
||||
usb::DestroyUsbEvents();
|
||||
controllers::Reset();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -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)))
|
||||
|
Loading…
x
Reference in New Issue
Block a user