ams: take care of most TODO C++20s
This commit is contained in:
@@ -19,21 +19,25 @@
|
||||
namespace ams::mitm {
|
||||
|
||||
/* TODO: C++20 Concepts will make this a lot less stupid. */
|
||||
class ModuleBase {};
|
||||
template<typename T>
|
||||
concept IsModule = requires(T, void *arg) {
|
||||
{ T::ThreadPriority } -> std::convertible_to<s32>;
|
||||
{ T::StackSize } -> std::convertible_to<size_t>;
|
||||
{ T::Stack } -> std::convertible_to<void *>;
|
||||
{ T::ThreadFunction(arg) } -> std::same_as<void>;
|
||||
};
|
||||
|
||||
#define DEFINE_MITM_MODULE_CLASS(ss, prio) class MitmModule : public ::ams::mitm::ModuleBase { \
|
||||
public: \
|
||||
static constexpr s32 ThreadPriority = prio; \
|
||||
static constexpr size_t StackSize = ss; \
|
||||
alignas(os::ThreadStackAlignment) static inline u8 Stack[StackSize]; \
|
||||
public: \
|
||||
static void ThreadFunction(void *); \
|
||||
#define DEFINE_MITM_MODULE_CLASS(ss, prio) class MitmModule { \
|
||||
public: \
|
||||
static constexpr s32 ThreadPriority = prio; \
|
||||
static constexpr size_t StackSize = ss; \
|
||||
alignas(os::ThreadStackAlignment) static inline u8 Stack[StackSize]; \
|
||||
public: \
|
||||
static void ThreadFunction(void *); \
|
||||
}
|
||||
|
||||
template<class M>
|
||||
template<class M> requires IsModule<M>
|
||||
struct ModuleTraits {
|
||||
static_assert(std::is_base_of<ModuleBase, M>::value, "Mitm Modules must inherit from ams::mitm::Module");
|
||||
|
||||
static constexpr void *Stack = &M::Stack[0];
|
||||
static constexpr size_t StackSize = M::StackSize;
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace ams::mitm {
|
||||
.main = Traits::ThreadFunction,
|
||||
.stack_mem = Traits::Stack,
|
||||
.priority = Traits::ThreadPriority,
|
||||
.stack_size = Traits::StackSize,
|
||||
.stack_size = static_cast<u32>(Traits::StackSize),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ namespace ams::pgl {
|
||||
constexpr sm::ServiceName ShellServiceName = sm::ServiceName::Encode("pgl");
|
||||
constexpr size_t ShellMaxSessions = 8; /* Official maximum is 8. */
|
||||
|
||||
/* TODO: C++20 constinit */ pgl::srv::ShellInterface g_shell_interface;
|
||||
constinit pgl::srv::ShellInterface g_shell_interface;
|
||||
|
||||
ALWAYS_INLINE std::shared_ptr<pgl::srv::ShellInterface> GetSharedPointerToShellInterface() {
|
||||
return ams::sf::ServiceObjectTraits<pgl::srv::ShellInterface>::SharedPointerHelper::GetEmptyDeleteSharedPointer(std::addressof(g_shell_interface));
|
||||
|
||||
Reference in New Issue
Block a user