Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #9391 from lioncash/find-str
IOS: Allow for heterogenous name lookup
  • Loading branch information
leoetlino committed Dec 30, 2020
2 parents 806a4f3 + 0e91470 commit 8a3b14d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 3 additions & 3 deletions Source/Core/Core/IOS/IOS.cpp
Expand Up @@ -409,7 +409,7 @@ bool Kernel::BootIOS(const u64 ios_title_id, const std::string& boot_content_pat
void Kernel::AddDevice(std::unique_ptr<Device::Device> device)
{
ASSERT(device->GetDeviceType() == Device::Device::DeviceType::Static);
m_device_map[device->GetDeviceName()] = std::move(device);
m_device_map.insert_or_assign(device->GetDeviceName(), std::move(device));
}

void Kernel::AddCoreDevices()
Expand Down Expand Up @@ -505,14 +505,14 @@ s32 Kernel::GetFreeDeviceID()
return -1;
}

std::shared_ptr<Device::Device> Kernel::GetDeviceByName(const std::string& device_name)
std::shared_ptr<Device::Device> Kernel::GetDeviceByName(std::string_view device_name)
{
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;
}

std::shared_ptr<Device::Device> EmulationKernel::GetDeviceByName(const std::string& device_name)
std::shared_ptr<Device::Device> EmulationKernel::GetDeviceByName(std::string_view device_name)
{
return Kernel::GetDeviceByName(device_name);
}
Expand Down
7 changes: 4 additions & 3 deletions Source/Core/Core/IOS/IOS.h
Expand Up @@ -10,6 +10,7 @@
#include <memory>
#include <mutex>
#include <string>
#include <string_view>
#include <vector>

#include "Common/CommonTypes.h"
Expand Down Expand Up @@ -110,14 +111,14 @@ class Kernel
void AddDevice(std::unique_ptr<Device::Device> device);
void AddCoreDevices();
void AddStaticDevices();
std::shared_ptr<Device::Device> GetDeviceByName(const std::string& device_name);
std::shared_ptr<Device::Device> GetDeviceByName(std::string_view device_name);
s32 GetFreeDeviceID();
IPCCommandResult OpenDevice(OpenRequest& request);

bool m_is_responsible_for_nand_root = false;
u64 m_title_id = 0;
static constexpr u8 IPC_MAX_FDS = 0x18;
std::map<std::string, std::shared_ptr<Device::Device>> m_device_map;
std::map<std::string, std::shared_ptr<Device::Device>, std::less<>> m_device_map;
std::mutex m_device_map_mutex;
// TODO: make this fdmap per process.
std::array<std::shared_ptr<Device::Device>, IPC_MAX_FDS> m_fdmap;
Expand All @@ -144,7 +145,7 @@ class EmulationKernel : public Kernel

// Get a resource manager by name.
// This only works for devices which are part of the device map.
std::shared_ptr<Device::Device> GetDeviceByName(const std::string& device_name);
std::shared_ptr<Device::Device> GetDeviceByName(std::string_view device_name);
};

// Used for controlling and accessing an IOS instance that is tied to emulation.
Expand Down

0 comments on commit 8a3b14d

Please sign in to comment.