diff options
author | kleines Filmröllchen <filmroellchen@serenityos.org> | 2022-08-18 21:44:31 +0200 |
---|---|---|
committer | Brian Gianforcaro <b.gianfo@gmail.com> | 2022-08-19 20:26:47 -0700 |
commit | 4809dc8ec28b8573b250a112b9a7dae4cde10e86 (patch) | |
tree | ad8e6c4f62fc8ed4b18f6c7fad6de928b973d0e2 /AK/Singleton.h | |
parent | f53aa5bfbb33ae469638f7ce20aec658354c2e7a (diff) | |
download | serenity-4809dc8ec28b8573b250a112b9a7dae4cde10e86.zip |
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.
Diffstat (limited to 'AK/Singleton.h')
-rw-r--r-- | AK/Singleton.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/AK/Singleton.h b/AK/Singleton.h index 3e67dea130..a0c6fa3290 100644 --- a/AK/Singleton.h +++ b/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); |