memory: Refactor SwapPT class

This commit is contained in:
EnderIce2 2024-10-26 03:25:36 +03:00
parent b6006e379d
commit 29896bb0a4
Signed by untrusted user who does not match committer: enderice2
GPG Key ID: EACC3AD603BAB4DD

View File

@ -31,12 +31,19 @@ namespace Memory
private: private:
PageTable *Replace = nullptr; PageTable *Replace = nullptr;
PageTable *Restore = nullptr; PageTable *Restore = nullptr;
bool Ignore;
public: public:
SwapPT(PageTable *ReplaceWith, SwapPT(auto ReplaceWith,
PageTable *RestoreWith = nullptr) auto _RestoreWith = nullptr)
: Replace(ReplaceWith) : Replace((PageTable *)ReplaceWith)
{ {
PageTable *RestoreWith = (PageTable *)_RestoreWith;
this->Ignore = Replace == RestoreWith;
if (this->Ignore)
return;
if (RestoreWith) if (RestoreWith)
Restore = RestoreWith; Restore = RestoreWith;
else else
@ -45,7 +52,13 @@ namespace Memory
Replace->Update(); Replace->Update();
} }
~SwapPT() { Restore->Update(); } ~SwapPT()
{
if (this->Ignore)
return;
Restore->Update();
}
}; };
} }