1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:27:35 +00:00

Kernel: Switch process file descriptor table from spinlock to mutex

There's no reason for this to use a spinlock. Instead, let's allow
threads to block if someone else is using the descriptor table.
This commit is contained in:
Andreas Kling 2022-01-29 01:29:07 +01:00
parent 8ebec2938c
commit b56646e293
16 changed files with 37 additions and 37 deletions

View file

@ -746,22 +746,22 @@ public:
WeakPtr<Process> m_process;
};
SpinlockProtected<OpenFileDescriptions>& fds() { return m_fds; }
SpinlockProtected<OpenFileDescriptions> const& fds() const { return m_fds; }
MutexProtected<OpenFileDescriptions>& fds() { return m_fds; }
MutexProtected<OpenFileDescriptions> const& fds() const { return m_fds; }
ErrorOr<NonnullRefPtr<OpenFileDescription>> open_file_description(int fd)
{
return m_fds.with([fd](auto& fds) { return fds.open_file_description(fd); });
return m_fds.with_shared([fd](auto& fds) { return fds.open_file_description(fd); });
}
ErrorOr<NonnullRefPtr<OpenFileDescription>> open_file_description(int fd) const
{
return m_fds.with([fd](auto& fds) { return fds.open_file_description(fd); });
return m_fds.with_shared([fd](auto& fds) { return fds.open_file_description(fd); });
}
ErrorOr<ScopedDescriptionAllocation> allocate_fd()
{
return m_fds.with([](auto& fds) { return fds.allocate(); });
return m_fds.with_exclusive([](auto& fds) { return fds.allocate(); });
}
private:
@ -770,7 +770,7 @@ private:
SpinlockProtected<Thread::ListInProcess> m_thread_list;
SpinlockProtected<OpenFileDescriptions> m_fds;
MutexProtected<OpenFileDescriptions> m_fds;
const bool m_is_kernel_process;
Atomic<State> m_state { State::Running };