Kernel: Add locking to inode's epoll list

This was prone to crashing :)
This commit is contained in:
Bananymous 2025-05-17 12:36:36 +03:00
parent b90cfa8e5c
commit 553c76ab0f
2 changed files with 4 additions and 0 deletions

View File

@ -175,6 +175,7 @@ namespace Kernel
private:
BAN::WeakPtr<SharedFileData> m_shared_region;
Mutex m_epoll_mutex;
BAN::LinkedList<class Epoll*> m_epolls;
friend class FileBackedRegion;
friend class OpenFileDescriptorSet;

View File

@ -264,12 +264,14 @@ namespace Kernel
BAN::ErrorOr<void> Inode::add_epoll(class Epoll* epoll)
{
LockGuard _(m_epoll_mutex);
TRY(m_epolls.push_back(epoll));
return {};
}
void Inode::del_epoll(class Epoll* epoll)
{
LockGuard _(m_epoll_mutex);
for (auto it = m_epolls.begin(); it != m_epolls.end(); it++)
{
if (*it != epoll)
@ -281,6 +283,7 @@ namespace Kernel
void Inode::epoll_notify(uint32_t event)
{
LockGuard _(m_epoll_mutex);
for (auto* epoll : m_epolls)
epoll->notify(this, event);
}