Browse Source

Kernel: Remove the limited use of AK::TypeTraits we had in the kernel

This was only used for VMObject and we can do without it there. This is
preparation for migrating to dynamic_cast-based helpers in userspace.
Andreas Kling 4 years ago
parent
commit
7c3b6b10e4

+ 6 - 4
Kernel/Syscalls/purge.cpp

@@ -42,8 +42,9 @@ int Process::sys$purge(int mode)
         NonnullRefPtrVector<PurgeableVMObject> vmobjects;
         {
             InterruptDisabler disabler;
-            MM.for_each_vmobject_of_type<PurgeableVMObject>([&](auto& vmobject) {
-                vmobjects.append(vmobject);
+            MM.for_each_vmobject([&](auto& vmobject) {
+                if (vmobject.is_purgeable())
+                    vmobjects.append(static_cast<PurgeableVMObject&>(vmobject));
                 return IterationDecision::Continue;
             });
         }
@@ -55,8 +56,9 @@ int Process::sys$purge(int mode)
         NonnullRefPtrVector<InodeVMObject> vmobjects;
         {
             InterruptDisabler disabler;
-            MM.for_each_vmobject_of_type<InodeVMObject>([&](auto& vmobject) {
-                vmobjects.append(vmobject);
+            MM.for_each_vmobject([&](auto& vmobject) {
+                if (vmobject.is_inode())
+                    vmobjects.append(static_cast<InodeVMObject&>(vmobject));
                 return IterationDecision::Continue;
             });
         }

+ 0 - 4
Kernel/VM/AnonymousVMObject.h

@@ -57,7 +57,3 @@ private:
 };
 
 }
-
-AK_BEGIN_TYPE_TRAITS(Kernel::AnonymousVMObject)
-static bool is_type(const Kernel::VMObject& vmobject) { return vmobject.is_anonymous(); }
-AK_END_TYPE_TRAITS()

+ 0 - 4
Kernel/VM/ContiguousVMObject.h

@@ -52,7 +52,3 @@ private:
 };
 
 }
-
-AK_BEGIN_TYPE_TRAITS(Kernel::ContiguousVMObject)
-static bool is_type(const Kernel::VMObject& vmobject) { return vmobject.is_contiguous(); }
-AK_END_TYPE_TRAITS()

+ 0 - 4
Kernel/VM/InodeVMObject.h

@@ -67,7 +67,3 @@ protected:
 };
 
 }
-
-AK_BEGIN_TYPE_TRAITS(Kernel::InodeVMObject)
-static bool is_type(const Kernel::VMObject& vmobject) { return vmobject.is_inode(); }
-AK_END_TYPE_TRAITS()

+ 4 - 2
Kernel/VM/MemoryManager.cpp

@@ -509,8 +509,10 @@ RefPtr<PhysicalPage> MemoryManager::allocate_user_physical_page(ShouldZeroFill s
     if (!page) {
         // We didn't have a single free physical page. Let's try to free something up!
         // First, we look for a purgeable VMObject in the volatile state.
-        for_each_vmobject_of_type<PurgeableVMObject>([&](auto& vmobject) {
-            int purged_page_count = vmobject.purge_with_interrupts_disabled({});
+        for_each_vmobject([&](auto& vmobject) {
+            if (!vmobject.is_purgeable())
+                return IterationDecision::Continue;
+            int purged_page_count = static_cast<PurgeableVMObject&>(vmobject).purge_with_interrupts_disabled({});
             if (purged_page_count) {
                 klog() << "MM: Purge saved the day! Purged " << purged_page_count << " pages from PurgeableVMObject{" << &vmobject << "}";
                 page = find_free_user_physical_page();

+ 0 - 4
Kernel/VM/PurgeableVMObject.h

@@ -65,7 +65,3 @@ private:
 };
 
 }
-
-AK_BEGIN_TYPE_TRAITS(Kernel::PurgeableVMObject)
-static bool is_type(const Kernel::VMObject& vmobject) { return vmobject.is_purgeable(); }
-AK_END_TYPE_TRAITS()

+ 0 - 1
Kernel/VM/VMObject.h

@@ -29,7 +29,6 @@
 #include <AK/InlineLinkedList.h>
 #include <AK/RefCounted.h>
 #include <AK/RefPtr.h>
-#include <AK/TypeCasts.h>
 #include <AK/Vector.h>
 #include <AK/Weakable.h>
 #include <Kernel/Lock.h>