mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:27:45 +00:00
Kernel: Switch singletons to use new Singleton class
MemoryManager cannot use the Singleton class because MemoryManager::initialize is called before the global constructors are run. That caused the Singleton to be re-initialized, causing it to create another MemoryManager instance. Fixes #3226
This commit is contained in:
parent
ba6e4fb77f
commit
d89582880e
46 changed files with 221 additions and 170 deletions
|
@ -24,6 +24,7 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <AK/Singleton.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <Kernel/FileSystem/DevPtsFS.h>
|
||||
|
@ -45,14 +46,10 @@ DevPtsFS::~DevPtsFS()
|
|||
{
|
||||
}
|
||||
|
||||
static HashTable<unsigned>* ptys;
|
||||
static AK::Singleton<HashTable<unsigned>> s_ptys;
|
||||
|
||||
bool DevPtsFS::initialize()
|
||||
{
|
||||
if (ptys == nullptr) {
|
||||
ptys = new HashTable<unsigned>();
|
||||
}
|
||||
|
||||
m_root_inode = adopt(*new DevPtsFSInode(*this, 1));
|
||||
m_root_inode->m_metadata.inode = { fsid(), 1 };
|
||||
m_root_inode->m_metadata.mode = 0040555;
|
||||
|
@ -104,12 +101,12 @@ RefPtr<Inode> DevPtsFS::get_inode(InodeIdentifier inode_id) const
|
|||
|
||||
void DevPtsFS::register_slave_pty(SlavePTY& slave_pty)
|
||||
{
|
||||
ptys->set(slave_pty.index());
|
||||
s_ptys->set(slave_pty.index());
|
||||
}
|
||||
|
||||
void DevPtsFS::unregister_slave_pty(SlavePTY& slave_pty)
|
||||
{
|
||||
ptys->remove(slave_pty.index());
|
||||
s_ptys->remove(slave_pty.index());
|
||||
}
|
||||
|
||||
DevPtsFSInode::DevPtsFSInode(DevPtsFS& fs, unsigned index)
|
||||
|
@ -144,7 +141,7 @@ KResult DevPtsFSInode::traverse_as_directory(Function<bool(const FS::DirectoryEn
|
|||
callback({ ".", identifier(), 0 });
|
||||
callback({ "..", identifier(), 0 });
|
||||
|
||||
for (unsigned pty_index : *ptys) {
|
||||
for (unsigned pty_index : *s_ptys) {
|
||||
String name = String::number(pty_index);
|
||||
InodeIdentifier identifier = { fsid(), pty_index_to_inode_index(pty_index) };
|
||||
callback({ name, identifier, 0 });
|
||||
|
@ -157,7 +154,7 @@ KResultOr<size_t> DevPtsFSInode::directory_entry_count() const
|
|||
{
|
||||
ASSERT(identifier().index() == 1);
|
||||
|
||||
return 2 + ptys->size();
|
||||
return 2 + s_ptys->size();
|
||||
}
|
||||
|
||||
RefPtr<Inode> DevPtsFSInode::lookup(StringView name)
|
||||
|
@ -170,7 +167,7 @@ RefPtr<Inode> DevPtsFSInode::lookup(StringView name)
|
|||
auto& fs = static_cast<DevPtsFS&>(this->fs());
|
||||
|
||||
auto pty_index = name.to_uint();
|
||||
if (pty_index.has_value() && ptys->contains(pty_index.value())) {
|
||||
if (pty_index.has_value() && s_ptys->contains(pty_index.value())) {
|
||||
return fs.get_inode({ fsid(), pty_index_to_inode_index(pty_index.value()) });
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
*/
|
||||
|
||||
#include <AK/HashTable.h>
|
||||
#include <AK/Singleton.h>
|
||||
#include <AK/StdLibExtras.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <Kernel/FileSystem/FIFO.h>
|
||||
|
@ -37,11 +38,10 @@
|
|||
|
||||
namespace Kernel {
|
||||
|
||||
static AK::Singleton<Lockable<HashTable<FIFO*>>> s_table;
|
||||
|
||||
static Lockable<HashTable<FIFO*>>& all_fifos()
|
||||
{
|
||||
static Lockable<HashTable<FIFO*>>* s_table;
|
||||
if (!s_table)
|
||||
s_table = new Lockable<HashTable<FIFO*>>;
|
||||
return *s_table;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
#include <AK/Assertions.h>
|
||||
#include <AK/HashMap.h>
|
||||
#include <AK/Singleton.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <Kernel/FileSystem/FileSystem.h>
|
||||
|
@ -37,12 +38,10 @@
|
|||
namespace Kernel {
|
||||
|
||||
static u32 s_lastFileSystemID;
|
||||
static HashMap<u32, FS*>* s_fs_map;
|
||||
static AK::Singleton<HashMap<u32, FS*>> s_fs_map;
|
||||
|
||||
static HashMap<u32, FS*>& all_fses()
|
||||
{
|
||||
if (!s_fs_map)
|
||||
s_fs_map = new HashMap<u32, FS*>();
|
||||
return *s_fs_map;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
*/
|
||||
|
||||
#include <AK/NonnullRefPtrVector.h>
|
||||
#include <AK/Singleton.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <Kernel/FileSystem/Custody.h>
|
||||
|
@ -38,15 +39,13 @@
|
|||
namespace Kernel {
|
||||
|
||||
static SpinLock s_all_inodes_lock;
|
||||
static AK::Singleton<InlineLinkedList<Inode>> s_list;
|
||||
|
||||
InlineLinkedList<Inode>& Inode::all_with_lock()
|
||||
{
|
||||
ASSERT(s_all_inodes_lock.is_locked());
|
||||
|
||||
static InlineLinkedList<Inode>* list;
|
||||
if (!list)
|
||||
list = new InlineLinkedList<Inode>;
|
||||
return *list;
|
||||
return *s_list;
|
||||
}
|
||||
|
||||
void Inode::sync()
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
*/
|
||||
|
||||
#include <AK/LexicalPath.h>
|
||||
#include <AK/Singleton.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <Kernel/Devices/BlockDevice.h>
|
||||
#include <Kernel/FileSystem/Custody.h>
|
||||
|
@ -40,13 +41,17 @@
|
|||
|
||||
namespace Kernel {
|
||||
|
||||
static VFS* s_the;
|
||||
static AK::Singleton<VFS> s_the;
|
||||
static constexpr int symlink_recursion_limit { 5 }; // FIXME: increase?
|
||||
static constexpr int root_mount_flags = MS_NODEV | MS_NOSUID | MS_RDONLY;
|
||||
|
||||
void VFS::initialize()
|
||||
{
|
||||
s_the.ensure_instance();
|
||||
}
|
||||
|
||||
VFS& VFS::the()
|
||||
{
|
||||
ASSERT(s_the);
|
||||
return *s_the;
|
||||
}
|
||||
|
||||
|
@ -55,7 +60,6 @@ VFS::VFS()
|
|||
#ifdef VFS_DEBUG
|
||||
klog() << "VFS: Constructing VFS";
|
||||
#endif
|
||||
s_the = this;
|
||||
}
|
||||
|
||||
VFS::~VFS()
|
||||
|
|
|
@ -78,6 +78,7 @@ public:
|
|||
int m_flags;
|
||||
};
|
||||
|
||||
static void initialize();
|
||||
static VFS& the();
|
||||
|
||||
VFS();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue