mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:17:44 +00:00
Kernel: Convert process file descriptor table to a SpinlockProtected
Instead of manually locking in the various member functions of Process::OpenFileDescriptions, simply wrap it in a SpinlockProtected.
This commit is contained in:
parent
93e90e16c3
commit
8ebec2938c
30 changed files with 257 additions and 190 deletions
|
@ -13,15 +13,17 @@ ErrorOr<FlatPtr> Process::sys$dup2(int old_fd, int new_fd)
|
|||
{
|
||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
|
||||
TRY(require_promise(Pledge::stdio));
|
||||
auto description = TRY(fds().open_file_description(old_fd));
|
||||
if (old_fd == new_fd)
|
||||
return m_fds.with([&](auto& fds) -> ErrorOr<FlatPtr> {
|
||||
auto description = TRY(fds.open_file_description(old_fd));
|
||||
if (old_fd == new_fd)
|
||||
return new_fd;
|
||||
if (new_fd < 0 || static_cast<size_t>(new_fd) >= OpenFileDescriptions::max_open())
|
||||
return EINVAL;
|
||||
if (!fds.m_fds_metadatas[new_fd].is_allocated())
|
||||
fds.m_fds_metadatas[new_fd].allocate();
|
||||
fds[new_fd].set(move(description));
|
||||
return new_fd;
|
||||
if (new_fd < 0 || static_cast<size_t>(new_fd) >= OpenFileDescriptions::max_open())
|
||||
return EINVAL;
|
||||
if (!m_fds.m_fds_metadatas[new_fd].is_allocated())
|
||||
m_fds.m_fds_metadatas[new_fd].allocate();
|
||||
m_fds[new_fd].set(move(description));
|
||||
return new_fd;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue