[hle/services] use ankerl:: for Service's function handlers map, use const char* instead of std::string{} (#3671)

Signed-off-by: lizzie <lizzie@eden-emu.dev>
Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/3671
Reviewed-by: DraVee <chimera@dravee.dev>
Reviewed-by: crueter <crueter@eden-emu.dev>
Co-authored-by: lizzie <lizzie@eden-emu.dev>
Co-committed-by: lizzie <lizzie@eden-emu.dev>
This commit is contained in:
lizzie 2026-03-08 20:50:29 +01:00 committed by crueter
parent 1864160326
commit 38aa2bc5e1
No known key found for this signature in database
GPG key ID: 425ACD2D4830EBC6
2 changed files with 20 additions and 24 deletions

View file

@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project // SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later // SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
@ -29,10 +29,13 @@ namespace Service {
return function_string; return function_string;
} }
ServiceFrameworkBase::ServiceFrameworkBase(Core::System& system_, const char* service_name_, ServiceFrameworkBase::ServiceFrameworkBase(Core::System& system_, const char* service_name_, u32 max_sessions_, InvokerFn* handler_invoker_)
u32 max_sessions_, InvokerFn* handler_invoker_) : SessionRequestHandler(system_.Kernel(), service_name_)
: SessionRequestHandler(system_.Kernel(), service_name_), system{system_}, , system{system_}
service_name{service_name_}, handler_invoker{handler_invoker_}, max_sessions{max_sessions_} {} , service_name{service_name_}
, handler_invoker{handler_invoker_}
, max_sessions{max_sessions_}
{}
ServiceFrameworkBase::~ServiceFrameworkBase() { ServiceFrameworkBase::~ServiceFrameworkBase() {
// Wait for other threads to release access before destroying // Wait for other threads to release access before destroying
@ -50,8 +53,7 @@ void ServiceFrameworkBase::RegisterHandlersBaseTipc(const FunctionInfoBase* func
// Usually this array is sorted by id already, so hint to insert at the end // Usually this array is sorted by id already, so hint to insert at the end
handlers_tipc.reserve(handlers_tipc.size() + n); handlers_tipc.reserve(handlers_tipc.size() + n);
for (std::size_t i = 0; i < n; ++i) for (std::size_t i = 0; i < n; ++i)
handlers_tipc.emplace_hint(handlers_tipc.cend(), functions[i].expected_header, handlers_tipc.emplace_hint(handlers_tipc.cend(), functions[i].expected_header, functions[i]);
functions[i]);
} }
void ServiceFrameworkBase::ReportUnimplementedFunction(HLERequestContext& ctx, void ServiceFrameworkBase::ReportUnimplementedFunction(HLERequestContext& ctx,

View file

@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project // SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later // SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
@ -8,8 +8,7 @@
#include <cstddef> #include <cstddef>
#include <mutex> #include <mutex>
#include <string> #include <ankerl/unordered_dense.h>
#include <boost/container/flat_map.hpp>
#include "common/common_types.h" #include "common/common_types.h"
#include "core/hle/service/hle_ipc.h" #include "core/hle/service/hle_ipc.h"
@ -78,13 +77,6 @@ protected:
[[nodiscard]] virtual std::unique_lock<std::mutex> LockService() noexcept { [[nodiscard]] virtual std::unique_lock<std::mutex> LockService() noexcept {
return std::unique_lock{lock_service}; return std::unique_lock{lock_service};
} }
/// System context that the service operates under.
Core::System& system;
/// Identifier string used to connect to the service.
std::string service_name;
private: private:
template <typename T> template <typename T>
friend class ServiceFramework; friend class ServiceFramework;
@ -106,16 +98,19 @@ private:
void RegisterHandlersBaseTipc(const FunctionInfoBase* functions, std::size_t n); void RegisterHandlersBaseTipc(const FunctionInfoBase* functions, std::size_t n);
void ReportUnimplementedFunction(HLERequestContext& ctx, const FunctionInfoBase* info); void ReportUnimplementedFunction(HLERequestContext& ctx, const FunctionInfoBase* info);
boost::container::flat_map<u32, FunctionInfoBase> handlers; protected:
boost::container::flat_map<u32, FunctionInfoBase> handlers_tipc; ankerl::unordered_dense::map<u32, FunctionInfoBase> handlers;
ankerl::unordered_dense::map<u32, FunctionInfoBase> handlers_tipc;
/// Used to gain exclusive access to the service members, e.g. from CoreTiming thread. /// Used to gain exclusive access to the service members, e.g. from CoreTiming thread.
std::mutex lock_service; std::mutex lock_service;
/// System context that the service operates under.
Core::System& system;
/// Identifier string used to connect to the service.
const char* service_name;
/// Function used to safely up-cast pointers to the derived class before invoking a handler. /// Function used to safely up-cast pointers to the derived class before invoking a handler.
InvokerFn* handler_invoker; InvokerFn* handler_invoker;
/// Maximum number of concurrent sessions that this service can handle. /// Maximum number of concurrent sessions that this service can handle.
u32 max_sessions; u32 max_sessions;
/// Flag to store if a port was already create/installed to detect multiple install attempts, /// Flag to store if a port was already create/installed to detect multiple install attempts,
/// which is not supported. /// which is not supported.
bool service_registered = false; bool service_registered = false;
@ -159,8 +154,7 @@ protected:
* @param max_sessions_ Maximum number of sessions that can be connected to this service at the * @param max_sessions_ Maximum number of sessions that can be connected to this service at the
* same time. * same time.
*/ */
explicit ServiceFramework(Core::System& system_, const char* service_name_, explicit ServiceFramework(Core::System& system_, const char* service_name_, u32 max_sessions_ = ServerSessionCountMax)
u32 max_sessions_ = ServerSessionCountMax)
: ServiceFrameworkBase(system_, service_name_, max_sessions_, Invoker) {} : ServiceFrameworkBase(system_, service_name_, max_sessions_, Invoker) {}
/// Registers handlers in the service. /// Registers handlers in the service.
@ -219,7 +213,7 @@ private:
static void Invoker(ServiceFrameworkBase* object, HandlerFnP<ServiceFrameworkBase> member, static void Invoker(ServiceFrameworkBase* object, HandlerFnP<ServiceFrameworkBase> member,
HLERequestContext& ctx) { HLERequestContext& ctx) {
// Cast back up to our original types and call the member function // Cast back up to our original types and call the member function
(static_cast<Self*>(object)->*static_cast<HandlerFnP<Self>>(member))(ctx); (static_cast<Self*>(object)->*HandlerFnP<Self>(member))(ctx);
} }
}; };