mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-04 05:20:30 +00:00
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:
parent
f53aa5bfbb
commit
4809dc8ec2
Notes:
sideshowbarker
2024-07-17 08:07:37 +09:00
Author: https://github.com/kleinesfilmroellchen Commit: https://github.com/SerenityOS/serenity/commit/4809dc8ec2 Pull-request: https://github.com/SerenityOS/serenity/pull/14914 Reviewed-by: https://github.com/bgianfo ✅
1 changed files with 13 additions and 0 deletions
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue