Registry.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. VERIFY(!m_root_directory->m_buses_directory.is_null());
  40. MUST(m_root_directory->m_buses_directory->m_child_components.with([&](auto& list) -> ErrorOr<void> {
  41. list.append(new_bus_directory);
  42. return {};
  43. }));
  44. }
  45. }