瀏覽代碼

AK: Add Singleton special-case constructor for SpinlockProtected

This will allow Singletons of that class to still be created when
SpinlockProtected can't be constructed without a lock rank argument
anymore.
kleines Filmröllchen 3 年之前
父節點
當前提交
4809dc8ec2
共有 1 個文件被更改,包括 13 次插入0 次删除
  1. 13 0
      AK/Singleton.h

+ 13 - 0
AK/Singleton.h

@@ -12,6 +12,7 @@
 #ifdef KERNEL
 #    include <Kernel/Arch/Processor.h>
 #    include <Kernel/Arch/ScopedCritical.h>
+#    include <Kernel/Locking/SpinlockProtected.h>
 #else
 #    include <sched.h>
 #endif
@@ -30,6 +31,18 @@ struct SingletonInstanceCreator {
     }
 };
 
+#ifdef KERNEL
+
+// FIXME: Find a nice way of injecting the lock rank into the singleton.
+template<typename T>
+struct SingletonInstanceCreator<Kernel::SpinlockProtected<T>> {
+    static Kernel::SpinlockProtected<T>* create()
+    {
+        return new Kernel::SpinlockProtected<T> { Kernel::LockRank::None };
+    }
+};
+#endif
+
 template<typename T, T* (*InitFunction)() = SingletonInstanceCreator<T>::create>
 class Singleton {
     AK_MAKE_NONCOPYABLE(Singleton);