mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 07:37:46 +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
1 changed files with 13 additions and 0 deletions
|
@ -12,6 +12,7 @@
|
||||||
#ifdef KERNEL
|
#ifdef KERNEL
|
||||||
# include <Kernel/Arch/Processor.h>
|
# include <Kernel/Arch/Processor.h>
|
||||||
# include <Kernel/Arch/ScopedCritical.h>
|
# include <Kernel/Arch/ScopedCritical.h>
|
||||||
|
# include <Kernel/Locking/SpinlockProtected.h>
|
||||||
#else
|
#else
|
||||||
# include <sched.h>
|
# include <sched.h>
|
||||||
#endif
|
#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>
|
template<typename T, T* (*InitFunction)() = SingletonInstanceCreator<T>::create>
|
||||||
class Singleton {
|
class Singleton {
|
||||||
AK_MAKE_NONCOPYABLE(Singleton);
|
AK_MAKE_NONCOPYABLE(Singleton);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue