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.
This commit is contained in:
kleines Filmröllchen 2022-08-18 21:44:31 +02:00 committed by Brian Gianforcaro
parent f53aa5bfbb
commit 4809dc8ec2
Notes: sideshowbarker 2024-07-17 08:07:37 +09:00

View file

@ -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);