@@ -235,7 +235,7 @@ Kernel::Kernel()
Kernel::~Kernel()
{
{
std::lock_guard<std::mutex> lock(m_device_map_mutex);
std::lock_guard lock(m_device_map_mutex);
m_device_map.clear();
}

@@ -417,15 +417,15 @@ void Kernel::AddCoreDevices()
m_fs = FS::MakeFileSystem();
ASSERT(m_fs);

std::lock_guard<std::mutex> lock(m_device_map_mutex);
std::lock_guard lock(m_device_map_mutex);
AddDevice(std::make_unique<Device::FS>(*this, "/dev/fs"));
AddDevice(std::make_unique<Device::ES>(*this, "/dev/es"));
AddDevice(std::make_unique<Device::DolphinDevice>(*this, "/dev/dolphin"));
}

void Kernel::AddStaticDevices()
{
std::lock_guard<std::mutex> lock(m_device_map_mutex);
std::lock_guard lock(m_device_map_mutex);

const Feature features = GetFeatures(GetVersion());

@@ -507,7 +507,7 @@ s32 Kernel::GetFreeDeviceID()

std::shared_ptr<Device::Device> Kernel::GetDeviceByName(const std::string& device_name)
{
std::lock_guard<std::mutex> lock(m_device_map_mutex);
std::lock_guard lock(m_device_map_mutex);
const auto iterator = m_device_map.find(device_name);
return iterator != m_device_map.end() ? iterator->second : nullptr;
}
@@ -167,7 +167,7 @@ IPCCommandResult BluetoothReal::IOCtlV(const IOCtlVRequest& request)
// HCI commands to the Bluetooth adapter
case USB::IOCTLV_USBV0_CTRLMSG:
{
std::lock_guard<std::mutex> lk(m_transfers_mutex);
std::lock_guard lk(m_transfers_mutex);
auto cmd = std::make_unique<USB::V0CtrlMessage>(m_ios, request);
const u16 opcode = Common::swap16(Memory::Read_U16(cmd->data_address));
if (opcode == HCI_CMD_READ_BUFFER_SIZE)
@@ -210,7 +210,7 @@ IPCCommandResult BluetoothReal::IOCtlV(const IOCtlVRequest& request)
case USB::IOCTLV_USBV0_BLKMSG:
case USB::IOCTLV_USBV0_INTRMSG:
{
std::lock_guard<std::mutex> lk(m_transfers_mutex);
std::lock_guard lk(m_transfers_mutex);
auto cmd = std::make_unique<USB::V0IntrMessage>(m_ios, request);
if (request.request == USB::IOCTLV_USBV0_INTRMSG)
{
@@ -594,7 +594,7 @@ bool BluetoothReal::OpenDevice(libusb_device* device)
// The callbacks are called from libusb code on a separate thread.
void BluetoothReal::HandleCtrlTransfer(libusb_transfer* tr)
{
std::lock_guard<std::mutex> lk(m_transfers_mutex);
std::lock_guard lk(m_transfers_mutex);
if (!m_current_transfers.count(tr))
return;

@@ -620,7 +620,7 @@ void BluetoothReal::HandleCtrlTransfer(libusb_transfer* tr)

void BluetoothReal::HandleBulkOrIntrTransfer(libusb_transfer* tr)
{
std::lock_guard<std::mutex> lk(m_transfers_mutex);
std::lock_guard lk(m_transfers_mutex);
if (!m_current_transfers.count(tr))
return;

@@ -66,7 +66,7 @@ void USBHost::DoState(PointerWrap& p)

bool USBHost::AddDevice(std::unique_ptr<USB::Device> device)
{
std::lock_guard<std::mutex> lk(m_devices_mutex);
std::lock_guard lk(m_devices_mutex);
if (m_devices.find(device->GetId()) != m_devices.end())
return false;

@@ -76,7 +76,7 @@ bool USBHost::AddDevice(std::unique_ptr<USB::Device> device)

std::shared_ptr<USB::Device> USBHost::GetDeviceById(const u64 device_id) const
{
std::lock_guard<std::mutex> lk(m_devices_mutex);
std::lock_guard lk(m_devices_mutex);
const auto it = m_devices.find(device_id);
if (it == m_devices.end())
return nullptr;
@@ -145,7 +145,7 @@ bool USBHost::AddNewDevices(std::set<u64>& new_devices, DeviceChangeHooks& hooks

void USBHost::DetectRemovedDevices(const std::set<u64>& plugged_devices, DeviceChangeHooks& hooks)
{
std::lock_guard<std::mutex> lk(m_devices_mutex);
std::lock_guard lk(m_devices_mutex);
for (auto it = m_devices.begin(); it != m_devices.end();)
{
if (plugged_devices.find(it->second->GetId()) == plugged_devices.end())
@@ -351,14 +351,14 @@ static const std::map<u8, const char*> s_transfer_types = {
void LibusbDevice::TransferEndpoint::AddTransfer(std::unique_ptr<TransferCommand> command,
libusb_transfer* transfer)
{
std::lock_guard<std::mutex> lk{m_transfers_mutex};
std::lock_guard lk{m_transfers_mutex};
m_transfers.emplace(transfer, std::move(command));
}

void LibusbDevice::TransferEndpoint::HandleTransfer(libusb_transfer* transfer,
std::function<s32(const TransferCommand&)> fn)
{
std::lock_guard<std::mutex> lk{m_transfers_mutex};
std::lock_guard lk{m_transfers_mutex};
const auto iterator = m_transfers.find(transfer);
if (iterator == m_transfers.cend())
{
@@ -396,7 +396,7 @@ void LibusbDevice::TransferEndpoint::HandleTransfer(libusb_transfer* transfer,

void LibusbDevice::TransferEndpoint::CancelTransfers()
{
std::lock_guard<std::mutex> lk(m_transfers_mutex);
std::lock_guard lk(m_transfers_mutex);
if (m_transfers.empty())
return;
INFO_LOG_FMT(IOS_USB, "Cancelling {} transfer(s)", m_transfers.size());
@@ -111,7 +111,7 @@ IPCCommandResult OH0::GetDeviceList(const IOCtlVRequest& request) const

const u8 interface_class = Memory::Read_U8(request.in_vectors[1].address);
u8 entries_count = 0;
std::lock_guard<std::mutex> lk(m_devices_mutex);
std::lock_guard lk(m_devices_mutex);
for (const auto& device : m_devices)
{
if (entries_count >= max_entries_count)
@@ -162,7 +162,7 @@ IPCCommandResult OH0::SetRhPortStatus(const IOCtlVRequest& request)

IPCCommandResult OH0::RegisterRemovalHook(const u64 device_id, const IOCtlRequest& request)
{
std::lock_guard<std::mutex> lock{m_hooks_mutex};
std::lock_guard lock{m_hooks_mutex};
// IOS only allows a single device removal hook.
if (m_removal_hooks.find(device_id) != m_removal_hooks.end())
return GetDefaultReply(IPC_EEXIST);
@@ -180,7 +180,7 @@ IPCCommandResult OH0::RegisterInsertionHook(const IOCtlVRequest& request)
if (HasDeviceWithVidPid(vid, pid))
return GetDefaultReply(IPC_SUCCESS);

std::lock_guard<std::mutex> lock{m_hooks_mutex};
std::lock_guard lock{m_hooks_mutex};
// TODO: figure out whether IOS allows more than one hook.
m_insertion_hooks[{vid, pid}] = request.address;
return GetNoReply();
@@ -191,7 +191,7 @@ IPCCommandResult OH0::RegisterInsertionHookWithID(const IOCtlVRequest& request)
if (!request.HasNumberOfValidVectors(3, 1))
return GetDefaultReply(IPC_EINVAL);

std::lock_guard<std::mutex> lock{m_hooks_mutex};
std::lock_guard lock{m_hooks_mutex};
const u16 vid = Memory::Read_U16(request.in_vectors[0].address);
const u16 pid = Memory::Read_U16(request.in_vectors[1].address);
const bool trigger_only_for_new_device = Memory::Read_U8(request.in_vectors[2].address) == 1;
@@ -222,7 +222,7 @@ bool OH0::HasDeviceWithVidPid(const u16 vid, const u16 pid) const

void OH0::OnDeviceChange(const ChangeEvent event, std::shared_ptr<USB::Device> device)
{
std::lock_guard<std::mutex> lk(m_devices_mutex);
std::lock_guard lk(m_devices_mutex);
if (event == ChangeEvent::Inserted)
TriggerHook(m_insertion_hooks, {device->GetVid(), device->GetPid()}, IPC_SUCCESS);
else if (event == ChangeEvent::Removed)
@@ -232,7 +232,7 @@ void OH0::OnDeviceChange(const ChangeEvent event, std::shared_ptr<USB::Device> d
template <typename T>
void OH0::TriggerHook(std::map<T, u32>& hooks, T value, const ReturnCode return_value)
{
std::lock_guard<std::mutex> lk{m_hooks_mutex};
std::lock_guard lk{m_hooks_mutex};
const auto hook = hooks.find(value);
if (hook == hooks.end())
return;
@@ -242,7 +242,7 @@ void OH0::TriggerHook(std::map<T, u32>& hooks, T value, const ReturnCode return_

std::pair<ReturnCode, u64> OH0::DeviceOpen(const u16 vid, const u16 pid)
{
std::lock_guard<std::mutex> lk(m_devices_mutex);
std::lock_guard lk(m_devices_mutex);

bool has_device_with_vid_pid = false;
for (const auto& device : m_devices)
@@ -120,7 +120,7 @@ IPCCommandResult USBV5ResourceManager::GetDeviceChange(const IOCtlRequest& reque
if (request.buffer_out_size != 0x180 || m_devicechange_hook_request)
return GetDefaultReply(IPC_EINVAL);

std::lock_guard<std::mutex> lk{m_devicechange_hook_address_mutex};
std::lock_guard lk{m_devicechange_hook_address_mutex};
m_devicechange_hook_request = std::make_unique<IOCtlRequest>(request.address);
// On the first call, the reply is sent immediately (instead of on device insertion/removal)
if (m_devicechange_first_call)
@@ -152,7 +152,7 @@ IPCCommandResult USBV5ResourceManager::Shutdown(const IOCtlRequest& request)
return GetDefaultReply(IPC_EINVAL);
}

std::lock_guard<std::mutex> lk{m_devicechange_hook_address_mutex};
std::lock_guard lk{m_devicechange_hook_address_mutex};
if (m_devicechange_hook_request)
{
m_ios.EnqueueIPCReply(*m_devicechange_hook_request, IPC_SUCCESS);
@@ -180,7 +180,7 @@ IPCCommandResult USBV5ResourceManager::HandleDeviceIOCtl(const IOCtlRequest& req
if (request.buffer_in == 0 || request.buffer_in_size != 0x20)
return GetDefaultReply(IPC_EINVAL);

std::lock_guard<std::mutex> lock{m_usbv5_devices_mutex};
std::lock_guard lock{m_usbv5_devices_mutex};
USBV5Device* device = GetUSBV5Device(request.buffer_in);
if (!device)
return GetDefaultReply(IPC_EINVAL);
@@ -190,7 +190,7 @@ IPCCommandResult USBV5ResourceManager::HandleDeviceIOCtl(const IOCtlRequest& req
void USBV5ResourceManager::OnDeviceChange(const ChangeEvent event,
std::shared_ptr<USB::Device> device)
{
std::lock_guard<std::mutex> lock{m_usbv5_devices_mutex};
std::lock_guard lock{m_usbv5_devices_mutex};
const u64 host_device_id = device->GetId();
if (event == ChangeEvent::Inserted)
{
@@ -222,7 +222,7 @@ void USBV5ResourceManager::OnDeviceChange(const ChangeEvent event,

void USBV5ResourceManager::OnDeviceChangeEnd()
{
std::lock_guard<std::mutex> lk{m_devicechange_hook_address_mutex};
std::lock_guard lk{m_devicechange_hook_address_mutex};
TriggerDeviceChangeReply();
++m_current_device_number;
}
@@ -233,7 +233,7 @@ void USBV5ResourceManager::TriggerDeviceChangeReply()
if (!m_devicechange_hook_request)
return;

std::lock_guard<std::mutex> lock{m_usbv5_devices_mutex};
std::lock_guard lock{m_usbv5_devices_mutex};
u8 num_devices = 0;
for (auto it = m_usbv5_devices.crbegin(); it != m_usbv5_devices.crend(); ++it)
{
@@ -80,7 +80,7 @@ IPCCommandResult USB_HIDv4::CancelInterrupt(const IOCtlRequest& request)

IPCCommandResult USB_HIDv4::GetDeviceChange(const IOCtlRequest& request)
{
std::lock_guard<std::mutex> lk{m_devicechange_hook_address_mutex};
std::lock_guard lk{m_devicechange_hook_address_mutex};
if (request.buffer_out == 0 || request.buffer_out_size != 0x600)
return GetDefaultReply(IPC_EINVAL);

@@ -96,7 +96,7 @@ IPCCommandResult USB_HIDv4::GetDeviceChange(const IOCtlRequest& request)

IPCCommandResult USB_HIDv4::Shutdown(const IOCtlRequest& request)
{
std::lock_guard<std::mutex> lk{m_devicechange_hook_address_mutex};
std::lock_guard lk{m_devicechange_hook_address_mutex};
if (m_devicechange_hook_request != 0)
{
Memory::Write_U32(0xffffffff, m_devicechange_hook_request->buffer_out);
@@ -140,7 +140,7 @@ void USB_HIDv4::DoState(PointerWrap& p)

std::shared_ptr<USB::Device> USB_HIDv4::GetDeviceByIOSID(const s32 ios_id) const
{
std::lock_guard<std::mutex> lk{m_id_map_mutex};
std::lock_guard lk{m_id_map_mutex};
const auto iterator = m_ios_ids.find(ios_id);
if (iterator == m_ios_ids.cend())
return nullptr;
@@ -150,7 +150,7 @@ std::shared_ptr<USB::Device> USB_HIDv4::GetDeviceByIOSID(const s32 ios_id) const
void USB_HIDv4::OnDeviceChange(ChangeEvent event, std::shared_ptr<USB::Device> device)
{
{
std::lock_guard<std::mutex> id_map_lock{m_id_map_mutex};
std::lock_guard id_map_lock{m_id_map_mutex};
if (event == ChangeEvent::Inserted)
{
s32 new_id = 0;
@@ -168,7 +168,7 @@ void USB_HIDv4::OnDeviceChange(ChangeEvent event, std::shared_ptr<USB::Device> d
}

{
std::lock_guard<std::mutex> lk{m_devicechange_hook_address_mutex};
std::lock_guard lk{m_devicechange_hook_address_mutex};
TriggerDeviceChangeReply();
}
}
@@ -184,7 +184,7 @@ void USB_HIDv4::TriggerDeviceChangeReply()
return;

{
std::lock_guard<std::mutex> lk(m_devices_mutex);
std::lock_guard lk(m_devices_mutex);
const u32 dest = m_devicechange_hook_request->buffer_out;
u32 offset = 0;
for (const auto& device : m_devices)
@@ -242,7 +242,7 @@ static std::vector<u8> GetDescriptors(const USB::Device& device)

std::vector<u8> USB_HIDv4::GetDeviceEntry(const USB::Device& device) const
{
std::lock_guard<std::mutex> id_map_lock{m_id_map_mutex};
std::lock_guard id_map_lock{m_id_map_mutex};

// The structure for a device section is as follows:
// 0-4 bytes: total size of the device data, including the size and the device ID
@@ -65,7 +65,7 @@ IPCCommandResult USB_HIDv5::IOCtlV(const IOCtlVRequest& request)
if (request.in_vectors.size() + request.io_vectors.size() != 2)
return GetDefaultReply(IPC_EINVAL);

std::lock_guard<std::mutex> lock{m_usbv5_devices_mutex};
std::lock_guard lock{m_usbv5_devices_mutex};
USBV5Device* device = GetUSBV5Device(request.in_vectors[0].address);
if (!device)
return GetDefaultReply(IPC_EINVAL);
@@ -74,7 +74,7 @@ IPCCommandResult USB_VEN::IOCtlV(const IOCtlVRequest& request)
if (request.in_vectors.size() + request.io_vectors.size() != s_num_vectors.at(request.request))
return GetDefaultReply(IPC_EINVAL);

std::lock_guard<std::mutex> lock{m_usbv5_devices_mutex};
std::lock_guard lock{m_usbv5_devices_mutex};
USBV5Device* device = GetUSBV5Device(request.in_vectors[0].address);
if (!device)
return GetDefaultReply(IPC_EINVAL);
@@ -169,7 +169,7 @@ std::string GetInputDisplay()

std::string input_display;
{
std::lock_guard<std::mutex> guard(s_input_display_lock);
std::lock_guard guard(s_input_display_lock);
for (int i = 0; i < 8; ++i)
{
if ((s_controllers & (1 << i)) != 0)
@@ -634,7 +634,7 @@ static void SetInputDisplayString(ControllerState padState, int controllerID)
display_str += " DISCONNECTED";
}

std::lock_guard<std::mutex> guard(s_input_display_lock);
std::lock_guard guard(s_input_display_lock);
s_InputDisplay[controllerID] = std::move(display_str);
}

@@ -765,7 +765,7 @@ static void SetWiiInputDisplayString(int remoteID, const DataReportBuilder& rpt,
display_str += Analog2DToString(right_stick.x, right_stick.y, " R-ANA", 31);
}

std::lock_guard<std::mutex> guard(s_input_display_lock);
std::lock_guard guard(s_input_display_lock);
s_InputDisplay[controllerID] = std::move(display_str);
}

@@ -2290,7 +2290,7 @@ bool NetPlayClient::IsLocalPlayer(const PlayerId pid) const

void NetPlayClient::SendTimeBase()
{
std::lock_guard<std::mutex> lk(crit_netplay_client);
std::lock_guard lk(crit_netplay_client);

if (netplay_client->m_timebase_frame % 60 == 0)
{
@@ -2430,7 +2430,7 @@ void SendPowerButtonEvent()

bool IsSyncingAllWiiSaves()
{
std::lock_guard<std::mutex> lk(crit_netplay_client);
std::lock_guard lk(crit_netplay_client);

if (netplay_client)
return netplay_client->GetNetSettings().m_SyncAllWiiSaves;
@@ -2457,13 +2457,13 @@ void SetupWiimotes()

void NetPlay_Enable(NetPlayClient* const np)
{
std::lock_guard<std::mutex> lk(crit_netplay_client);
std::lock_guard lk(crit_netplay_client);
netplay_client = np;
}

void NetPlay_Disable()
{
std::lock_guard<std::mutex> lk(crit_netplay_client);
std::lock_guard lk(crit_netplay_client);
netplay_client = nullptr;
}
} // namespace NetPlay
@@ -2474,7 +2474,7 @@ void NetPlay_Disable()
// Actual Core function which is called on every frame
bool SerialInterface::CSIDevice_GCController::NetPlay_GetInput(int pad_num, GCPadStatus* status)
{
std::lock_guard<std::mutex> lk(NetPlay::crit_netplay_client);
std::lock_guard lk(NetPlay::crit_netplay_client);

if (NetPlay::netplay_client)
return NetPlay::netplay_client->GetNetPads(pad_num, NetPlay::s_si_poll_batching, status);
@@ -2484,7 +2484,7 @@ bool SerialInterface::CSIDevice_GCController::NetPlay_GetInput(int pad_num, GCPa

bool WiimoteEmu::Wiimote::NetPlay_GetWiimoteData(int wiimote, u8* data, u8 size, u8 reporting_mode)
{
std::lock_guard<std::mutex> lk(NetPlay::crit_netplay_client);
std::lock_guard lk(NetPlay::crit_netplay_client);

if (NetPlay::netplay_client)
return NetPlay::netplay_client->WiimoteUpdate(wiimote, data, size, reporting_mode);
@@ -2495,7 +2495,7 @@ bool WiimoteEmu::Wiimote::NetPlay_GetWiimoteData(int wiimote, u8* data, u8 size,
// Sync the info whether a button was pressed or not. Used for the reconnect on button press feature
bool Wiimote::NetPlay_GetButtonPress(int wiimote, bool pressed)
{
std::lock_guard<std::mutex> lk(NetPlay::crit_netplay_client);
std::lock_guard lk(NetPlay::crit_netplay_client);

// Use the reporting mode 0 for the button pressed event, the real ones start at RT_REPORT_CORE
static const u8 BUTTON_PRESS_REPORTING_MODE = 0;
@@ -2521,7 +2521,7 @@ bool Wiimote::NetPlay_GetButtonPress(int wiimote, bool pressed)
// also called from ---GUI--- thread when starting input recording
u64 ExpansionInterface::CEXIIPL::NetPlay_GetEmulatedTime()
{
std::lock_guard<std::mutex> lk(NetPlay::crit_netplay_client);
std::lock_guard lk(NetPlay::crit_netplay_client);

if (NetPlay::netplay_client)
return NetPlay::netplay_client->GetInitialRTCValue();
@@ -2533,7 +2533,7 @@ u64 ExpansionInterface::CEXIIPL::NetPlay_GetEmulatedTime()
// return the local pad num that should rumble given a ingame pad num
int SerialInterface::CSIDevice_GCController::NetPlay_InGamePadToLocalPad(int numPAD)
{
std::lock_guard<std::mutex> lk(NetPlay::crit_netplay_client);
std::lock_guard lk(NetPlay::crit_netplay_client);

if (NetPlay::netplay_client)
return NetPlay::netplay_client->InGamePadToLocalPad(numPAD);
@@ -307,7 +307,7 @@ struct CompressAndDumpState_args

static void CompressAndDumpState(CompressAndDumpState_args save_args)
{
std::lock_guard<std::mutex> lk(*save_args.buffer_mutex);
std::lock_guard lk(*save_args.buffer_mutex);

// ScopeGuard is used here to ensure that g_compressAndDumpStateSyncEvent.Set()
// will be called and that it will happen after the IOFile is closed.
@@ -419,7 +419,7 @@ void SaveAs(const std::string& filename, bool wait)

// Then actually do the write.
{
std::lock_guard<std::mutex> lk(g_cs_current_buffer);
std::lock_guard lk(g_cs_current_buffer);
g_current_buffer.resize(buffer_size);
ptr = &g_current_buffer[0];
p.SetMode(PointerWrap::MODE_WRITE);
@@ -576,7 +576,7 @@ void LoadAs(const std::string& filename)
// Save temp buffer for undo load state
if (!Movie::IsJustStartingRecordingInputFromSaveState())
{
std::lock_guard<std::mutex> lk(g_cs_undo_load_buffer);
std::lock_guard lk(g_cs_undo_load_buffer);
SaveToBuffer(g_undo_load_buffer);
if (Movie::IsMovieActive())
Movie::SaveRecording(File::GetUserPath(D_STATESAVES_IDX) + "undo.dtm");
@@ -649,12 +649,12 @@ void Shutdown()
// this gives a better guarantee to free the allocated memory right NOW (as opposed to, actually,
// never)
{
std::lock_guard<std::mutex> lk(g_cs_current_buffer);
std::lock_guard lk(g_cs_current_buffer);
std::vector<u8>().swap(g_current_buffer);
}

{
std::lock_guard<std::mutex> lk(g_cs_undo_load_buffer);
std::lock_guard lk(g_cs_undo_load_buffer);
std::vector<u8>().swap(g_undo_load_buffer);
}
}
@@ -716,7 +716,7 @@ void Flush()
// Load the last state before loading the state
void UndoLoadState()
{
std::lock_guard<std::mutex> lk(g_cs_undo_load_buffer);
std::lock_guard lk(g_cs_undo_load_buffer);
if (!g_undo_load_buffer.empty())
{
if (File::Exists(File::GetUserPath(D_STATESAVES_IDX) + "undo.dtm") || (!Movie::IsMovieActive()))