kern: use optimized red black tree finds for remaining holdouts

This commit is contained in:
Michael Scire 2021-10-23 21:58:48 -07:00
parent 436613401a
commit 89926f44c6
5 changed files with 36 additions and 37 deletions

View file

@ -705,10 +705,10 @@ namespace ams::kern {
KScopedSchedulerLock sl;
/* Try to find the page in the partially used list. */
auto it = m_partially_used_tlp_tree.find(KThreadLocalPage(util::AlignDown(GetInteger(addr), PageSize)));
auto it = m_partially_used_tlp_tree.find_key(util::AlignDown(GetInteger(addr), PageSize));
if (it == m_partially_used_tlp_tree.end()) {
/* If we don't find it, it has to be in the fully used list. */
it = m_fully_used_tlp_tree.find(KThreadLocalPage(util::AlignDown(GetInteger(addr), PageSize)));
it = m_fully_used_tlp_tree.find_key(util::AlignDown(GetInteger(addr), PageSize));
R_UNLESS(it != m_fully_used_tlp_tree.end(), svc::ResultInvalidAddress());
/* Release the region. */
@ -749,9 +749,9 @@ namespace ams::kern {
KThreadLocalPage *tlp = nullptr;
{
KScopedSchedulerLock sl;
if (auto it = m_partially_used_tlp_tree.find(KThreadLocalPage(util::AlignDown(GetInteger(addr), PageSize))); it != m_partially_used_tlp_tree.end()) {
if (auto it = m_partially_used_tlp_tree.find_key(util::AlignDown(GetInteger(addr), PageSize)); it != m_partially_used_tlp_tree.end()) {
tlp = std::addressof(*it);
} else if (auto it = m_fully_used_tlp_tree.find(KThreadLocalPage(util::AlignDown(GetInteger(addr), PageSize))); it != m_fully_used_tlp_tree.end()) {
} else if (auto it = m_fully_used_tlp_tree.find_key(util::AlignDown(GetInteger(addr), PageSize)); it != m_fully_used_tlp_tree.end()) {
tlp = std::addressof(*it);
} else {
return nullptr;

View file

@ -1324,33 +1324,16 @@ namespace ams::kern {
KThread::ListAccessor accessor;
const auto end = accessor.end();
/* Define helper object to find the thread. */
class IdObjectHelper : public KAutoObjectWithListContainer::ListType::value_type {
private:
u64 m_id;
public:
explicit IdObjectHelper(u64 id) : m_id(id) { /* ... */ }
virtual u64 GetId() const override { return m_id; }
};
/* Find the object with the right id. */
const auto it = accessor.find(IdObjectHelper(thread_id));
/* Check to make sure we found the thread. */
if (it == end) {
return nullptr;
if (const auto it = accessor.find_key(thread_id); it != end) {
/* Try to open the thread. */
if (KThread *thread = static_cast<KThread *>(std::addressof(*it)); AMS_LIKELY(thread->Open())) {
MESOSPHERE_ASSERT(thread->GetId() == thread_id);
return thread;
}
}
/* Get the thread. */
KThread *thread = static_cast<KThread *>(std::addressof(*it));
/* Open the thread. */
if (AMS_LIKELY(thread->Open())) {
MESOSPHERE_ASSERT(thread->GetId() == thread_id);
return thread;
}
/* We failed to find the thread. */
/* We failed to find or couldn't open the thread. */
return nullptr;
}