Registry.cpp 1.3 KB

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