Serenity Operating System
at master 55 lines 1.4 kB view raw
1/* 2 * Copyright (c) 2022, Liav A. <liavalb@hotmail.co.il> 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#include <AK/Singleton.h> 8#include <AK/StringView.h> 9#include <Kernel/FileSystem/SysFS/Registry.h> 10#include <Kernel/Sections.h> 11 12namespace Kernel { 13 14static Singleton<SysFSComponentRegistry> s_the; 15 16SysFSComponentRegistry& SysFSComponentRegistry::the() 17{ 18 return *s_the; 19} 20 21UNMAP_AFTER_INIT void SysFSComponentRegistry::initialize() 22{ 23 VERIFY(!s_the.is_initialized()); 24 s_the.ensure_instance(); 25} 26 27UNMAP_AFTER_INIT SysFSComponentRegistry::SysFSComponentRegistry() 28 : m_root_directory(SysFSRootDirectory::create()) 29{ 30} 31 32UNMAP_AFTER_INIT void SysFSComponentRegistry::register_new_component(SysFSComponent& component) 33{ 34 SpinlockLocker locker(m_root_directory_lock); 35 MUST(m_root_directory->m_child_components.with([&](auto& list) -> ErrorOr<void> { 36 list.append(component); 37 return {}; 38 })); 39} 40 41SysFSBusDirectory& SysFSComponentRegistry::buses_directory() 42{ 43 return *m_root_directory->m_buses_directory; 44} 45 46void SysFSComponentRegistry::register_new_bus_directory(SysFSDirectory& new_bus_directory) 47{ 48 VERIFY(!m_root_directory->m_buses_directory.is_null()); 49 MUST(m_root_directory->m_buses_directory->m_child_components.with([&](auto& list) -> ErrorOr<void> { 50 list.append(new_bus_directory); 51 return {}; 52 })); 53} 54 55}