mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2024-11-15 01:26:34 +00:00
kern: optimize handle table layout
This commit is contained in:
parent
4a1ca5f39b
commit
a5aed96b80
2 changed files with 11 additions and 26 deletions
|
@ -54,14 +54,10 @@ namespace ams::kern {
|
||||||
}
|
}
|
||||||
|
|
||||||
union EntryInfo {
|
union EntryInfo {
|
||||||
struct {
|
u16 linear_id;
|
||||||
u16 linear_id;
|
s16 next_free_index;
|
||||||
u16 type;
|
|
||||||
} info;
|
|
||||||
s32 next_free_index;
|
|
||||||
|
|
||||||
constexpr ALWAYS_INLINE u16 GetLinearId() const { return info.linear_id; }
|
constexpr ALWAYS_INLINE u16 GetLinearId() const { return linear_id; }
|
||||||
constexpr ALWAYS_INLINE u16 GetType() const { return info.type; }
|
|
||||||
constexpr ALWAYS_INLINE s32 GetNextFreeIndex() const { return next_free_index; }
|
constexpr ALWAYS_INLINE s32 GetNextFreeIndex() const { return next_free_index; }
|
||||||
};
|
};
|
||||||
private:
|
private:
|
||||||
|
@ -187,17 +183,8 @@ namespace ams::kern {
|
||||||
NOINLINE Result Reserve(ams::svc::Handle *out_handle);
|
NOINLINE Result Reserve(ams::svc::Handle *out_handle);
|
||||||
NOINLINE void Unreserve(ams::svc::Handle handle);
|
NOINLINE void Unreserve(ams::svc::Handle handle);
|
||||||
|
|
||||||
template<typename T>
|
NOINLINE Result Add(ams::svc::Handle *out_handle, KAutoObject *obj);
|
||||||
ALWAYS_INLINE Result Add(ams::svc::Handle *out_handle, T *obj) {
|
NOINLINE void Register(ams::svc::Handle handle, KAutoObject *obj);
|
||||||
static_assert(std::is_base_of<KAutoObject, T>::value);
|
|
||||||
return this->Add(out_handle, obj, obj->GetTypeObj().GetClassToken());
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
ALWAYS_INLINE void Register(ams::svc::Handle handle, T *obj) {
|
|
||||||
static_assert(std::is_base_of<KAutoObject, T>::value);
|
|
||||||
return this->Register(handle, obj, obj->GetTypeObj().GetClassToken());
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
ALWAYS_INLINE bool GetMultipleObjects(T **out, const ams::svc::Handle *handles, size_t num_handles) const {
|
ALWAYS_INLINE bool GetMultipleObjects(T **out, const ams::svc::Handle *handles, size_t num_handles) const {
|
||||||
|
@ -242,8 +229,6 @@ namespace ams::kern {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
NOINLINE Result Add(ams::svc::Handle *out_handle, KAutoObject *obj, u16 type);
|
|
||||||
NOINLINE void Register(ams::svc::Handle handle, KAutoObject *obj, u16 type);
|
|
||||||
|
|
||||||
constexpr ALWAYS_INLINE s32 AllocateEntry() {
|
constexpr ALWAYS_INLINE s32 AllocateEntry() {
|
||||||
MESOSPHERE_ASSERT_THIS();
|
MESOSPHERE_ASSERT_THIS();
|
||||||
|
|
|
@ -74,7 +74,7 @@ namespace ams::kern {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result KHandleTable::Add(ams::svc::Handle *out_handle, KAutoObject *obj, u16 type) {
|
Result KHandleTable::Add(ams::svc::Handle *out_handle, KAutoObject *obj) {
|
||||||
MESOSPHERE_ASSERT_THIS();
|
MESOSPHERE_ASSERT_THIS();
|
||||||
KScopedDisableDispatch dd;
|
KScopedDisableDispatch dd;
|
||||||
KScopedSpinLock lk(m_lock);
|
KScopedSpinLock lk(m_lock);
|
||||||
|
@ -87,8 +87,8 @@ namespace ams::kern {
|
||||||
const auto linear_id = this->AllocateLinearId();
|
const auto linear_id = this->AllocateLinearId();
|
||||||
const auto index = this->AllocateEntry();
|
const auto index = this->AllocateEntry();
|
||||||
|
|
||||||
m_entry_infos[index].info = { .linear_id = linear_id, .type = type };
|
m_entry_infos[index].linear_id = linear_id;
|
||||||
m_objects[index] = obj;
|
m_objects[index] = obj;
|
||||||
|
|
||||||
obj->Open();
|
obj->Open();
|
||||||
|
|
||||||
|
@ -131,7 +131,7 @@ namespace ams::kern {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KHandleTable::Register(ams::svc::Handle handle, KAutoObject *obj, u16 type) {
|
void KHandleTable::Register(ams::svc::Handle handle, KAutoObject *obj) {
|
||||||
MESOSPHERE_ASSERT_THIS();
|
MESOSPHERE_ASSERT_THIS();
|
||||||
KScopedDisableDispatch dd;
|
KScopedDisableDispatch dd;
|
||||||
KScopedSpinLock lk(m_lock);
|
KScopedSpinLock lk(m_lock);
|
||||||
|
@ -149,8 +149,8 @@ namespace ams::kern {
|
||||||
/* Set the entry. */
|
/* Set the entry. */
|
||||||
MESOSPHERE_ASSERT(m_objects[index] == nullptr);
|
MESOSPHERE_ASSERT(m_objects[index] == nullptr);
|
||||||
|
|
||||||
m_entry_infos[index].info = { .linear_id = linear_id, .type = type };
|
m_entry_infos[index].linear_id = linear_id;
|
||||||
m_objects[index] = obj;
|
m_objects[index] = obj;
|
||||||
|
|
||||||
obj->Open();
|
obj->Open();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue